The challenge
The shortest code by character count to generate seven segment display representation of a given hex number.
Input
Input is made out of digits [0-9] and hex characters in both lower and upper case [a-fA-F] only. There is no need to handle special cases.
Output
Output will be the seven segment representation of the input, using those ASCII faces:
_ _ _ _ _ _ _ _ _ _ _ _
| | | _| _| |_| |_ |_ | |_| |_| |_| |_ | _| |_ |_
|_| | |_ _| | _| |_| | |_| _| | | |_| |_ |_| |_ |
Restrictions
The use of the following is forbidden: eval, exec, system, figlet, toilet and external libraries.
Test cases:
Input:
deadbeef
Output:
_ _ _ _ _
_||_ |_| _||_ |_ |_ |_
|_||_ | ||_||_||_ |_ |
Input:
4F790D59
Output:
_ _ _ _ _ _
|_||_ ||_|| | _||_ |_|
|| | _||_||_| _| _|
Code count includes input/output (i.e full program).
Man... can't beat the perl. Here's some py3k at 163 chars.
Explanation. First here's what it looked like completely unoptimized:
Then i go about finding ways to pack the data. First I can transform
a
into a big, long integer, last element first, 8 bits at a time. That produces, in octal:0o2645541764615736673577046675463463347404657
. written in hex, that's0xb4b61fa637bdbbbf89b7b3399b9e09af
, 90 chars shorter than the list of octals. To use it you have to rewrite code, of course. That looks likeb
can be concatenated,''.join(b)
is 26 chars, including the quotes. the lookup function must also change to support this.Next I just eliminate all unneeded syntax by folding functions and constants into the expression, and that's pretty much it.
It's possible to tighten up the printing a bit, too. Instead of joining the lines, just print them immediately. this results in a modified
fmt()
:Ruby: 175
And when a bit more readable...