31
\$\begingroup\$

Write the shortest program which will take a string of numbers (of up to at least 20 length) as input, and display the output using the standard digital clock style numbers. For instance for input 81, a solution with ascii output would give:

 _
|_|  |
|_|  |

Graphical output is also acceptable, if it helps.

\$\endgroup\$
4

33 Answers 33

1
2
0
\$\begingroup\$

JavaScript 137 133

r=(x,i=0,o='')=>{for(m of x){c="ŞHŦŬxļ>ňžŸ".charCodeAt(m)>>1<<i
for(j=3;j--;)o+=c&256>>j?'|_'[j%2]:' '}
return i<7?r(x,i+3,o+"\n"):o}
\$\endgroup\$
0
\$\begingroup\$

JavaScript (Node.js), 188 bytes

s=>[0,1,2].map(i=>s.replace(/./g,e=>[(t=(h,j='|',k=' ')=>(''+h).includes(e)?j:k)(2370+(b='5689'),' _ ','   '),t(104+b)+t(234+b,'_')+t(2347890),t(12680)+t(230+b,'_')+t(3704+b)][i])).join`
`

Try it online!

Not the shortest but uses a different approach.

\$\endgroup\$
-1
\$\begingroup\$

Perl, 145 characters

$i=<>;for$s(6,3,0){for($i=~/./g){$v=(175,9,158,155,57,179,183,137,191,187)[$_]>>$s;$o.=($v&4?'|':$").($v&2?'_':$").($v&1?'|':$")}$o.="
"}print$o

Ungolfed:

# Read STDIN
$i = <>;
# Amount to bit shift later
for $s (6,3,0)
{
  # For each character C from STDIN
  for ($i =~ /./g)
  {
    # Get the Cth array index, bit shifted right by $s
    $v = (175, 9, 158, 155, 57, 179, 183, 137, 191, 187)[$_]>>$s;
    # Concatenate each character if the bitwise masked value says it should be there
    $o .= ($v & 4 ? '|' : $") .
          ($v & 2 ? '_' : $") .
          ($v & 1 ? '|' : $");
  }
  # Concatenate a newline
  $o .= "
";
}
# Print the result
print $o;
\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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