17
2
You probably all know the 7-segment display which can display among other things all digits from \$0\dots 9\$:
Challenge
We only consider the segments \$\texttt{A}\dots\texttt{G}\$, your task is to decode a single digit given which segments are turned on.
This can be encoded as an 8-bit integer, here's a table of each digit with their binary representation and the corresponding little-endian and big-endian values:
$$ \begin{array}{c|c|rr|rr} \text{Digit} & \texttt{.ABCDEFG} & \text{Little-endian} && \text{Big-endian} & \\ \hline 0 & \texttt{01111110} & 126 & \texttt{0x7E} & 126 & \texttt{0x7E} \\ 1 & \texttt{00110000} & 48 & \texttt{0x30} & 12 & \texttt{0x0C} \\ 2 & \texttt{01101101} & 109 & \texttt{0x6D} & 182 & \texttt{0xB6} \\ 3 & \texttt{01111001} & 121 & \texttt{0x79} & 158 & \texttt{0x9E} \\ 4 & \texttt{00110011} & 51 & \texttt{0x33} & 204 & \texttt{0xCC} \\ 5 & \texttt{01011011} & 91 & \texttt{0x5B} & 218 & \texttt{0xDA} \\ 6 & \texttt{01011111} & 95 & \texttt{0x5F} & 250 & \texttt{0xFA} \\ 7 & \texttt{01110000} & 112 & \texttt{0x70} & 14 & \texttt{0x0E} \\ 8 & \texttt{01111111} & 127 & \texttt{0x7F} & 254 & \texttt{0xFE} \\ 9 & \texttt{01111011} & 123 & \texttt{0x7B} & 222 & \texttt{0xDE} \end{array} $$
Rules & I/O
- Input will be one of
- single integer (like in the table above one of the two given orders)
- a list/array/.. of bits
- a string consisting of characters
ABCDEFG
(you may assume it's sorted, as an exampleABC
encodes \$7\$), their case is your choice (not mixed-case)
- Output will be the digit it encodes
- You may assume no invalid inputs (invalid means that there is no corresponding digit)
Tests
Since this challenge allows multiple representations, please refer to the table.
Related. – ბიმო – 2018-10-21T16:46:47.820
Can we accept an integer (or array) in any specified bit-order or just the two shown? – Jonathan Allan – 2018-10-21T17:07:26.163
@JonathanAllan: I'll clarify, only the ones already shown. – ბიმო – 2018-10-21T19:37:10.403
Ohhh crap, you don't have to handle all input types? Only one? Whoops... – Magic Octopus Urn – 2018-10-22T15:42:36.750
@MagicOctopusUrn: Yes indeed :) – ბიმო – 2018-10-22T17:43:19.697