9
\$\begingroup\$

Given A and B, where A is the scale of a Digital LED Pattern B. Parse pattern B and print the number.

input:

1
 _  _  _  _     _     _     _  _  _  _  _     _ 
 _| _| _|| ||_||_   ||_ |_|| |  ||_||_||_   ||_|
|_  _||_ |_|  | _|  ||_|  ||_|  |  |  | _|  ||_|

output:

2320451640799518

input:

2
 __  __
   |   | 
 __| __|
|      |
|__  __|

output:

23

Rules:

  • Use STDIN/STDOUT for input/output

  • I tried to mimic this question as much as possible, but I think code-golf suits this one better.

  • Shortest code (in bytes) wins

\$\endgroup\$
2
  • \$\begingroup\$ Shouldn't that be "Given a number A and 2*A+1 lines of input…"? \$\endgroup\$
    – reima
    Commented Jan 28, 2014 at 21:16
  • \$\begingroup\$ @reima You are right, the pattern will be 2*A+1 lines. I wanted the style of the question to be as similar to its original as possible, so I changed it so that it doesn't mention the number of lines at all. \$\endgroup\$
    – daniero
    Commented Jan 28, 2014 at 22:01

1 Answer 1

2
\$\begingroup\$

Ruby, 151 characters

s,*r=*$<;c=r[s=s.to_i]
i=0;(n=(r[0][i+1]+c[i]+c[i+s,2]+r[-1][i]).tr(" |_","01").to_i 2
$><<(0..9).find{|j|0x3df9778eb5c5b>>5*j&31==n};i+=s+2)while b[i]

Leaves out digits it cannot recognise, but some invalid digits are recognised nevertheless.

Assumes the lines are padded with spaces to their full length.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.