Skip to main content
9 of 9
minor update
Arnauld
  • 197.8k
  • 20
  • 180
  • 650

JavaScript (Node.js), 265 bytes

f=n=>n?`01238888765${n<1e4?4:48888}`.replace(e=/\d/g,y=>`4567|3210
`.replace(e,x=>"_ \\/.'|"[q=y/2&2|x>3,y&8?1:(k='40321123'[j=~~('0x'+(1e6+'1023405671567899AB99A899CB99C')[y%4+~-(n/10**q%10)*4])]^x%4?2045>>j&1:'0122233346545'[j])^0xCC6600>>k*4+q&1]))+f(n/1e4|0):''

Try it online!

Encoding

Each digit pattern is a 4x4 matrix consisting of 7 distinct characters. Each character is encoded as a single decimal digit from 0 to 6:

0: "_"
1: " "
2: "\"
3: "/"
4: "."
5: "'"
6: "|"

All matrices are built with 13 distinct rows, encoded as a single hexadecimal digit from 0 to C:

0: 1111 for "    "
1: 0001 for "___ "
2: 2111 for "\   "
3: 1211 for " \  "
4: 1121 for "  \ "
5: 1131 for "  / "
6: 1311 for " /  "
7: 3111 for "/   "
8: 1114 for "   ."
9: 1116 for "   |"
A: 1115 for "   '"
B: 0004 for "___."
C: 0005 for "___'"

So, each matrix is fully described by a sequence of 4 hexadecimal digits. For instance, the matrix for 7 is encoded as B99A:

B99A -> 0004 -> "___."
        1116    "   |"
        1116    "   |"
        1115    "   '"

The leading sequence is 0000 and is omitted. The other sequences are stored as:

1e6 + '1023405671567899AB99A899CB99C'

which expands to:

0      1    2    3    4    5    6    7    8    9
(0000) 1000 0001 0234 0567 1567 899A B99A 899C B99C

Each matrix row is made of a 'background' character appearing 3 times and a 'foreground' character appearing only once (or not at all). So the rows can be encoded as:

  • the position of the 'foreground' character (0 for rightmost to 3 for leftmost, or 4 if none)
  • the 'background' character (which is always either 0 for "_" or 1 for " ")
  • the 'foreground' character

This is summarized in the following table:

 ID | string | digits | FG position | BG char. | FG char.
----+--------+--------+-------------+----------+----------
  0 | "    " |  1111  |      4      |    1     |    0
  1 | "___ " |  0001  |      0      |    0     |    1
  2 | "\   " |  2111  |      3      |    1     |    2
  3 | " \  " |  1211  |      2      |    1     |    2
  4 | "  \ " |  1121  |      1      |    1     |    2
  5 | "  / " |  1131  |      1      |    1     |    3
  6 | " /  " |  1311  |      2      |    1     |    3
  7 | "/   " |  3111  |      3      |    1     |    3
  8 | "   ." |  1114  |      0      |    1     |    4
  9 | "   |" |  1116  |      0      |    1     |    6
  A | "   '" |  1115  |      0      |    1     |    5
  B | "___." |  0004  |      0      |    0     |    4
  C | "___'" |  0005  |      0      |    0     |    5
----+--------+--------+-------------+----------+----------
                             |           |          |
                             |           |          +--> stored as "0122233346545"
                             |           +-------------> stored as the bit mask 2045
                             +-------------------------> stored as "40321123"
Arnauld
  • 197.8k
  • 20
  • 180
  • 650