Write a program or function that increments an integer. The input and output must be in one of the ASCII art fonts provided below.
__ ___ ___ __ ___ _ ___ ___ ___ ___
/ )(__ \ (__ ) /. | | __) / ) (__ )( _ )/ _ \ / _ \
)( / _/ (_ \(_ _)|__ \/ _ \ / / / _ \\_ /( (_) )
(__)(____)(___/ (_) (___/\___/(_/ \___/ (_/ \___/
__ ____ ____ ___ ___ ___ ____ ____ ___ __
/ \ (___ \( __ \ / _ \ / __) / __)(__ )/ _ \/ _ \ / \
(_/ / / __/ (__ ((__ ((___ \( _ \ / / ) _ (\__ )( 0 )
(__) (____)(____/ (__/(____/ \___/ (_/ \____/(___/ \__/
_ ____ _____ _ _ ____ __ _____ ___ ___ ___
/ ||___ \ |___ / | || | | ___| / /_ |___ | ( _ ) / _ \ / _ \
| | __) | |_ \ | || |_ |___ \ | '_ \ / / / _ \ | (_) || | | |
| | / __/ ___) ||__ _| ___) || (_) | / / | (_) | \__, || |_| |
|_||_____||____/ |_| |____/ \___/ /_/ \___/ /_/ \___/
___ ___ ___ ___ ___ ___ ___ ___ ___ ___
|_ | |_ ||_ || | || _|| _||_ || . || . || |
_| |_ | _||_ ||_ ||_ || . | | || . ||_ || | |
|_____||___||___| |_||___||___| |_||___||___||___|
_ ___ ____ _ _ ___ __ ____ ___ ___ __
/ | |_ ) |__ / | | | | __| / / |__ | ( _ ) / _ \ / \
| | / / |_ \ |_ _| |__ \ / _ \ / / / _ \ \_, / | () |
|_| /___| |___/ |_| |___/ \___/ /_/ \___/ /_/ \__/
___ ___ ____ ____ ____ ____ ____ ___ ___ ___
< / |_ | |_ / / / / / __/ / __//_ / ( _ ) / _ \ / _ \
/ / / __/ _/_ < /_ _/ /__ \ / _ \ / / / _ | \_, // // /
/_/ /____/ /____/ /_/ /____/ \___/ /_/ \___/ /___/ \___/
_ ____ _____ _ _ ____ __ _____ ___ ___ ___
/ | |___ \ |___ / | || | | ___| / /_ |___ | ( _ ) / _ \ / _ \
| | __) | |_ \ | || |_ |___ \ | '_ \ / / / _ \ | (_) | | | | |
| | / __/ ___) | |__ _| ___) | | (_) | / / | (_) | \__, | | |_| |
|_| |_____| |____/ |_| |____/ \___/ /_/ \___/ /_/ \___/
. .-. -. . . .-. .-. .-. .-. .-. .-.
'| .'' -| `-| ``. |-. .' )-( `-| |\|
' `-- -' ' --' `-' ' `-' `-' `-'
__ __ __ _ __ _ _ _
/| _)__)|_||_ |_ /(_)(_|/ \
| /____) |__)|_) / (_) _|\_/
____ ______ ______ _____ ______ ______ ______ ______ ______ ______
|_ | |__ ||__ || | | | __|| __|| || __ || __ || |
_| |_ | __||__ ||__ ||__ || __ ||_ || __ ||__ || -- |
|______||______||______| |__| |______||______| |____||______||______||______|
_ _ __ __ ___ _ __ __
-/ _) _) (_/ /_ /_ _/ (_) (__) / )
/ /__ __) / __) (__) / (__) __/ (__/
_ ___ ___ ___ ___ ___ ___ ___ ___
| | | | | | | / | | | | | /|
+ -+- -+- -+- -+- |-+- + -+- -+-| | + |
| | | | | | | / | | | |/ |
--- --- --- --- --- --- --- ---
_ __ __ ___ ___ __ __ __
/ ) ) / / / / / ( )(__) / )
/ .--' -/ '--/ '--. /_ -/- ./' / / /
/ (__ ___/ / ___) (__)/ (__) / (__/
, __ ___ ____ __ _____ __ __ __
/| / ) / \ | | | / / / \ / | / \
| / __/ |__|_ |___ | __ / \__/ \_/| | |
| / \ | \ |/ \ / / \ | | |
| /___ \___/ | \___/ \__/ / \__/ | \__/
Input
A integer from 1 to 32767, represented in your choice of ASCII art font from the options provided. Extra whitespace is not ok. Input can be newline-separated text, arrays of arrays of characters, etc.
Output
The number one greater than the input, represented in the same ASCII art font. Extra whitespace is ok. Output can be newline-separated text, arrays of arrays of characters, etc.
Scoring
Code golf.
Sample data
Input:
____ ______ ______
|_ | |__ ||__ |
_| |_ | __||__ |
|______||______||______|
Output:
____ ______ _____
|_ | |__ || | |
_| |_ | __||__ |
|______||______| |__|
-
\$\begingroup\$ The white space in your list of fonts seems somewhat erratic; do we have to duplicate this? \$\endgroup\$Neil– Neil2025年05月26日 05:51:25 +00:00Commented May 26 at 5:51
-
\$\begingroup\$ No - there should be no rows of columns of whitespace outside the digits in the input. 0 or 1 columns of whitespace between digits in input at your choice. Rows or columns of whitespace outside digits in output as you please. 0 or 1 columns of whitespace between digits in output at your choice. \$\endgroup\$Steve Bennett– Steve Bennett2025年05月26日 06:36:12 +00:00Commented May 26 at 6:36
-
1\$\begingroup\$ So the columns of whitespace in some of the fonts are not really part of the font definition and can be removed? \$\endgroup\$Arnauld– Arnauld2025年05月26日 15:11:10 +00:00Commented May 26 at 15:11
-
\$\begingroup\$ Yes, indeed.(...) \$\endgroup\$Steve Bennett– Steve Bennett2025年05月26日 20:19:52 +00:00Commented May 26 at 20:19
5 Answers 5
Ruby, 258 bytes
->s{y=n=0;t=s.size/9
t.times{|i|j='/\/ /__| |_|| ((( '.index s[1+3*i+=t]+s[2+3*i+=t]
n=n*10+j/2+j%2*6}
(["%d"%-~n]*3*$/).bytes{|k|print k>10?' _ __ __ __ _ __ _ _ / \/| _)__)|_||_ |_ /(_)(_|\_/ | /____) |__)|_) / (_) _|'[k%48*3+y,3]:$/%y+=30}}
Uses the smallest font on the list, which is equal size 3x3 characters. The number of digits in the input is therefore t=s.size/9
, rounded down.
Function takes a newline-separated string as an argument and prints a newline-separated string.
Each digit is identified by the 1st character on the 2nd and 3rd row. These are combined into a 2-character string and searched for in a magic string. The digit is given by j/2
with a correction of j%2/6
(since 7
returns an incorrect index of 3 instead of 14, when it finds the two spaces that straddle the data for digits 1
and 2
.) The total is kept in n
n+1 = -~n
is converted into 3 copies of the string representation of n, separated by newlines. This is then processed one Ascii code at a time. if the Ascii code is not newline, we find the correct 3 output characters in the big string with index [k%48*3+y,3]
. If it is a newline, we output a newline and increment y
by 30 to find the correct output characters for the next row.
JavaScript (ES6), 192 bytes
Uses the 12th font without the columns of whitespace.
f=(s,n,S=` 455
7 639
C2+2B
836 A
111 `[R="replace"](/.+/g,s=>(n+"")[R](e=/\w/g,n=>s[R](e,c=>" --/__"[[4061,41,411,795,98,603,2779,28,987,1883][n]>>"0x"+c-1&1&&c]||"|"))))=>s?f(s!=S&&s,-~n):S
Method
The digits in this font can be described with 12 separate parts of one or several characters. They are either on or off. We label them with hexadecimal digits 1
to C
. The pattern also includes spaces and a +
in the center.
455 ___
7 639 | |/|
C2+2B -> |-+-|
836 A |/| |
111 ---
Labels greater than \5ドル\$ are reserved for the most common character |
so that a lookup table is only needed for the other ones. The order of the labels was otherwise chosen to minimize the size of the bitmasks once converted to decimal (many equivalent solutions exist).
We generate the ASCII-art representation of all numbers from \1ドル\$ to \$+\infty\$1 until we find the one matching the input, then return the next one.
1: The first iteration actually attempts to render "undefined"
, leading to a string that doesn't match any valid input.
Python 3, 241 bytes
i=input
j=''.join
d=j(map(j,zip(i(),i(),i())))
c="| _/(\)"*49;f=j(c[x//49]+c[x//7]+c[x] for x in b'KkWG19lr]rra2@13ro1r>9lxQraNr1')
n=0
while d:n=n*10+f.index(d[:9])//9;d=d[9:]
for y in 0,1,2:print(j(f[int(x)*9:][:9]for x in str(n+1))[y::3])
Input and output use input()
and print()
for stdin/stdout.
Using the 3x3 monospace font.
Explanation of implementation:
- Font
f
is stored column by column in compressed format, 3 symbols per character. - Input lines are interleaved to
d
d
is parsed 9 characters at a time, and index in font is used as the numeric value of the digit- Output is formatted line by line
Charcoal, 67 bytes
≔⪪"{➙d↗≧?↥R(⊞νu»I3§±↑⊞φ⌊⎇Lχ8YΣZ|+&ςR↥ÞJ~Z⌊C"9ε↑⪪⍘⊕⍘⪪⭆θ⭆⟦ζηθ⟧§λκ9εε3
Try it online! Link is to verbose version of code. Uses the smallest monospaced font in the list. Explanation: Processes the data vertically, rotating the input and output.
"..." Compressed rotated font data
⪪ 9 Split into individual digits
≔ ε Save into variable
⭆θ⭆⟦ζηθ⟧§λκ Input rotated and joined
⪪ 9 Split into individual digits
⍘ ε Decoded using font as custom base
⊕ Incremented
⍘ ε Encoded using font as custom base
⪪ 3 Split into columns
↑ Output rotated
If Charcoal had a transpose operator then ⭆θ⭆⟦ζηθ⟧§λκ
could be ⪫Z⮌E3Sω
for a saving of 4
bytes.
Jelly, 65 bytes
"®ṇs¢Ị8h5ƘPḟẈḊṚÐTḄɓ¡ṇƓ4ḶVṠ:6ÐḷKñœ’ṃ" /|)(\_"s3s3ɓỴZs3iⱮ@Ṗ}Ḍ‘ṃZ€ZY
A full program that accepts a string argument and prints to stdout.
How?
"...’ṃ" /|)(\_"s3s3ɓỴZs3iⱮ@Ṗ}Ḍ‘ṃZ€ZY - Link: list of characters, InputArt
"...’ - 2143653348009571447353888914930329561628051130270532338528823129948739132031
ṃ" /|)(\_" - in base seven with digits 0-7 = "_ /|)(\"
s3s3 - split into threes, split into threes
ɓ - new dyadic chain - f(InputArt, Parts=that)...
Ỵ - split {InputArt} at newline characters
Z - transpose
s3 - split into threes -> InputParts
iⱮ@ - 1-indices of {InputParts} in:
Ṗ} - {Parts} without the right
or 0 if not found
Ḍ - cast from decimal
‘ - increment
ṃ - in base ten with digits 1-9,0 = {Parts}
Z€ - transpose each
Z - transpose
Y - join with newline characters
- implicit, smashing print