JavaScript (148145)
148 145
Since JavaScript doesn’t really have standard input/output, this is written as a function that takes a string and returns the output as a string.
function r(n){for(i=o="",b=" |_ |"|_\n|",L=n.length;i<3*L;)o+=b[(c="ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L])>>(i++/L|0)*3)&1]+b[c&2]+b[c&4]+(i%L&1]+b[c&2]+b[c&4]+b[i%L?" "0:"\n");return3];return o}
Spaced out:
function r(n)
{
for (i = o = "", b = " |_ |"|_\n|", L = n.length; i < 3*L; )
o += b [ (c = "ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L]) >> (i++/L|0)*3) & 1]1 ] +
b [ c&2 ] +
b [ c&4 ] +
(b [ i%L ? " "0 : "\n");3 ]; // space or newline
return o
}
Here’s how it works:
Every digit shape is encoded in a Unicode character consisting of 9 bits.
The first three bits are for the first row, etc.
In each group of three bits, the first specifies whether the first character is
|
or space, the second whether it’s_
or space, and the third again|
or space.These three bits are retrieved as
c&1
,c&2
andc&4
, which are then used as indexes into the stringb
.At each iteration,
i%L
is the “x-coordinate”, i.e. the digit within the inputn
At each iteration,
i/L
is the “y-coordinate”, i.e. the row, but we need|0
to make it an integerFinally, the spaces between the digits and the newlines between the lines are also retrieved by indexing into
b
, re-using the space character and the otherwise unused position 3 in that string! :)