Read a retro display
Ruby, 184 bytes
a=0
l=$<.map{|x|x.bytes.map{|y|y==32?0:1}+[0]*2}
(0..l[0].count-1).map{|i|l[0][i]+2*l[1][i]+4*l[2][i]}.each{|x|
x>0?(a=x+2*a):(p Hash[[40,6,32,20,18,26,42,8,44,64].zip(0..9)][a];a=0)}
Explanation
- takes the input from stdin
- converts the strings to binary sequences, 1/0 for segment on/off
- encodes columns to 3bit binary number
- encodes sequences of 3 bit numbers to 9 bit numbers, use '0' columns as stop symbols
- use a lookup table to convert the 9 bit numbers to digits
This is my first code-golf. Thanks for the fun!
Pyth, 33 30 bytes
sm@."/9Àøw"%%Csd409hTcC.z*3d
Here's the idea: Once we transpose the input, and split into digits, we can sort of hash the individual digit strings and assign them to their values.
sm@."/9Àøw"%%Csd409hTcC.z*3d Implicit: z=input
C.z Transpose input.
c *3d Split that on " ", a space between digits.
m@."/9Àøw"%%Csd409hT Map the following lambda d over that. d is a digit string.
Csd Flatten the digit string, and convert from base 256.
% 409 Modulo that by 409
% hT and then by 11. All digits go to a distinct num mod 11.
."/9Àøw" The compressed string "03924785/61".
@ Index into that string.
s Flatten and implicitly output.
Try it here.
Japt, 119 bytes
Ur"[|_]"1 z r" +
"R x1 qR² £"11
1 1
1151151
111
15111
115 1
1
115 1
111
1511
111
15 1
11511
111
115 1
111
11"q5 bXÃq
Try it here!
Oh geez, this one's really long. I don't think I have finished golfing.
Explanation
Preparation
We take the input and convert any |_
to 1
. Then we transpose, strip out ending spaces, and split along double-newlines.
Translation
We map over the resulting array and find the index where the form appears in a reference array. Here's a diagram to help:
MAPITEM
11
1 1 --> This same form appears at index 0 in the reference array
11 |
|
V
change the mapitem to 0!
After that, we join the array of numbers and output!
NOTE: You may be wondering why we have to change each art character to a series of 1's. This is because there seems to be a bug (or something like that) which doesn't let me store the characters as is with |_
.