| Bytes | Lang | Time | Link |
|---|---|---|---|
| 247 | Swift 6 | 250425T181455Z | macOSist |
| 174 | Perl 5 pF | 250514T160837Z | Xcali |
| nan | Bespoke | 250421T195301Z | m90 |
| 184 | Ruby p | 250423T044114Z | Value In |
| 080 | 05AB1E | 250415T105444Z | Kevin Cr |
| 131 | GolfScript | 250414T224033Z | Twilight |
| 077 | Jelly | 250414T185051Z | Jonathan |
| 093 | Japt R | 250413T141426Z | Shaggy |
| 142 | Uiua | 250412T193429Z | noodle p |
| 200 | JavaScript Node.js | 250413T032454Z | l4m2 |
| 089 | Charcoal | 250412T202718Z | Neil |
| 151 | Retina 0.8.2 | 250412T160941Z | Neil |
Swift 6, 312 308 303 284 278 247 bytes
{s in[0]+s
s.indices.map{if $0%10<1{let d=s[$0...].prefix(10).map{"NUMBERZERO I BI TRI FOUR FIFTH SEXTET SEVENTH INTEIGHT DIGITNINE".split{$0<"!"}[$0]}
print((s.count<2 ?"PUSH ":($0<1 ?"PUT ":"CONTINUED ")+d.map{_ in"X"}+":")+{d.joined}()(" "))}}}
Perl 5 -pF, 174 bytes
s|.|$t=$&;($r=!($p%10)&&($p?"
CONTINUED":@F>1?PUT:PUSH)).$".(X x(@F-$p++>10?10:@F-$p+1).":")x$r=~/T/.(NUMBERZERO,I,BI,TRI,FOUR,FIFTH,SEXTET,SEVENTH,INTEIGHT,DIGITNINE)[$t]|ge
Bespoke, 1782 1702 1692 1669 1654 bytes
AAAAAAA AAAAAAAA A A AAAAAAA AAAAAAA AA AAAA AAA AA AA AAAAA AAAAAAAA AAAAAA AAA AA AAAAAA AAAAAA AAAAAAAA AAAA AAAAAA AA AAA AA AA AAAAAAA AAAAAAAA AAAAAAAAAA AA AAAA AAAAAAA AAA AA A AAA AA AAA AA AAAAAAA AAA AAAA A AAAA AAA AAAAAAAA AAAAA AAAAAAA AAAAAAA AA AAAAAAAA AAAAAAAA AAAAAAA AA AAAAAAAA AAAAA AA AAAAAAAA AAAAAAA AA AAAA AAAAAAA AAA AAA AAAAAAAAAA A AAAAAAAAAA AAA AAAAA AAAAAAAAA AAAAAA A AA A A AAAAAAAAA AAAAA AAAAAA A AAA A AA AAAA AAAAAAA AAA AAA AA AAAAAAAAAA AAAAAAAAAA AAA AAAA AAAAA A AAAAAA AAAAAAAA AAA AAAAAA AAA AA AAAA AAA AAAAA AAAA AAA AAAAAAA AAA AAA AA AAAAAAAAAA AAAAA AA AAAAAAAAA AAA AAAAAAAAA AA AAAAAA AAAAAAA AAAAA AAAAA AAAAAAAAA AA AAAAAAAAA AA AAA AAAAAAAAAA AA AAAA A A AA AAA AAAAAAA A A AAAAAAA AAA AAAAAAAAAA A AAAAAAAAA AAAAAA AAA AAAAAAAAAA AAAAA AAAAAAAAAA AA AAAA AAAA AAAAAAAAA AA AAAAAAAA AA AAA AAAAAAAAAA AAAAAAAAA A AAA AAAA AAAAAAAAA AAAAAAAAAA AAAAAA AAAA AAAAAAAAAA AAAA AAAAAAAAA AA AA AAAAAAA AA AAAAAAAA AAA AAA AAAA AAAAAAAAA AAAA AAA AA AAAAAAAA AAAAAAAAAA AAAAAAA AAAAAAA AAAAAA AA AAAA AA AA AAAAA AAAAAAA AA AAAAAAA AAAA A A AAAAAA AA AAA AA A AAAAAAAAAA AAAAAAAA AAAAAA AAAAAAAA AAAAAAA AA AAAA AAAAAAA AAAAAAA AAA AA AAAAAAAA AAAAAAAA AAAAAA AA AAAAAAAA AAAAAAAA AA AAAA AAAAAAA AAA AA A AAA AA AAAAA AAAAAAAA AAAAAAA AAAAAAAAA AAAAAAAA AA AAA AAAA AAAA AAAAA A AAAAAAAAA AAAAAAA AAAA A A AAAAAAA AAA AAAAAAA AAAAAAA AAAAAA AA AAAAAAAA AAAAAAAA AA AAAAAA AAA AA AAAAA AAAAAAAAA AAAAAAAA AAAAA AA AAAAA AAAAAAA AAAA A A AAAA AA AA AAAAA AAAAAAA AAA A AA AAAA AAAAAAAAA AAA AAAAAAAAAA AAAAAAAA AA A AA AAAAAAAAA AA AAAAAAA AA A AAA AAAAAAAAA AA AAAAA A AAA AA A AAAAAAAAAA AAAA AAAA AA AAAAA
With mnemonics and indentation:
CONTROL FUNCTION X:I
CONTROL DOWHILE
DO COPY
PUT XX:BI FIFTH
STACKTOP MODULO
PUT XX:SEXTET SEXTET
STACKTOP PLUS
OUTPUT CH
PUT XX:BI SEVENTH
STACKTOP QUOTIENTOF
DO COPY
CONTROL END
DO P
PUT XX:TRI BI
CONTROL END
PUSH I
PUSH TRI
STACKTOP MINUS
CONTROL DOWHILE
DO TURNOVER
STACKTOP PLUSONE
DO TURNOVER
INPUT CH
STACKTOP PLUSONE
DO COPY
CONTROL END
PUT XXXXXXXXXX:I NUMBERZERO TRI FIFTH DIGITNINE SEXTET I BI I I
CONTINUED XXXXX:SEXTET I TRI I BI
PUSH SEVENTH
PUT XXX:BI NUMBERZERO NUMBERZERO
PUT XXXX:FIFTH I SEXTET INTEIGHT
PUT XXXXXX:TRI BI FOUR TRI FIFTH FOUR
PUT XXXXXXX:TRI TRI BI NUMBERZERO FIFTH BI DIGITNINE
PUT XXXXXXXXX:BI SEXTET SEVENTH FIFTH FIFTH DIGITNINE BI DIGITNINE BI
PUT XXXXXXXXXX:BI FOUR I I BI TRI SEVENTH I I SEVENTH
PUT XXXXXXXXXX:I DIGITNINE SEXTET TRI NUMBERZERO FIFTH NUMBERZERO BI FOUR FOUR
CONTINUED XX:INTEIGHT BI
PUT XXXXXXXXXX:DIGITNINE I TRI FOUR DIGITNINE NUMBERZERO SEXTET FOUR NUMBERZERO FOUR
CONTINUED XX:BI SEVENTH
DO TURNOVER
PUT XXX:FOUR DIGITNINE FOUR
PUT XX:INTEIGHT NUMBERZERO
CONTROL DOWHILE
OUTPUT CH
PUSH BI
DO COPYN
CONTROL IF
CONTROL CALL X:I
OUTPUT CH
PUT XX:I NUMBERZERO
STACKTOP MODULO
STACKTOP PLUSONE
DO COPY
CONTROL DOWHILE
PUT XX:INTEIGHT INTEIGHT
OUTPUT CH
STACKTOP MINUSONE
DO COPY
CONTROL END
DO P
PUT XX:FIFTH INTEIGHT
CONTROL OTHERWISE
STACKTOP LT
PUT XXXX:FOUR FIFTH I DIGITNINE
CONTROL CALL X:I
CONTROL END
CONTROL DOWHILE
OUTPUT CH
STACKTOP MINUSONE
DO SWITCH
PUT XX:FIFTH DIGITNINE
STACKTOP MINUS
DO COPYN
CONTROL CALL X:I
PUSH BI
DO COPYN
CONTROL END
H SV
PUSH DIGITNINE
PUT XXXXXXXXXX:INTEIGHT BI I BI DIGITNINE BI SEVENTH BI I TRI
CONTINUED XX:FIFTH I
PUT XX:I NUMBERZERO
PUSH FOUR
DO COPYN
The input is all read onto the stack while being counted, then reversed and processed.
The function takes a number and outputs a word by taking the number modulo 25 to determine each letter (from B to Z), and dividing by 27 to get the next number. It also pushes 32 (the character code for a space).
The numbers that represent the digits' mnemonics are kept at the bottom of the stack and accessed with DO COPYN on negative values.
-21 from emanresu A with the observation that the letter A is not needed in the output.
-30 by changing the divisor to 27, giving some flexibility in the numbers.
-14 with other improvements from emanresu A: copy the value 10 at the end (for the number of digits processed and the line feed), and omit the last CONTROL END.
-15 from l4m2 by removing the CONTROL RETURN.
-5 by using H SV to double-pop.
-28 from l4m2 by pushing 32 in the function.
-15 with some rearrangement and adjustment, putting the copy for the check for the special case of 1 digit inside the loop.
Ruby -p, 184 bytes
d=%w"NUMBERZERO I BI TRI FOUR FIFTH SEXTET SEVENTH INTEIGHT DIGITNINE"
~/$/>1?gsub(/.{1,10}/){[$`[0]?"
CONTINUED":"PUT",?X*$&.size+?:,$&.bytes.map{d[_1-48]}]*' '}:$_="PUSH "+d[$_.to_i]
Explanation
#!ruby -p # Take input as $_, run code, then print $_
d=%w"NUMBERZERO I BI TRI FOUR FIFTH SEXTET SEVENTH INTEIGHT DIGITNINE"
# Initialize mnemonic list
~/$/>1? # If input length (position of end-of-string) > 1
gsub(/.{1,10}/){ # Replace every 1-10 characters of $_ with...
[ # Array to join arguments later
$`[0]? # If $` (string before regex match) has characters
"\nCONTINUED" # CONTINUED (with newline) if true
:"PUT", # otherwise PUT
?X*$&.size+?:, # "X" repeated by length of match, then ":"
$&.bytes.map{ # For each byte value in regex match
d[_1-48] # Pick the corresponding mnemonic
}
]*' ' # Join with spaces
} # (end gsub block)
: # Otherwise (one-digit number)
$_="PUSH "+d[$_.to_i] # Set $_ to PUSH + the corresponding mnemonic
05AB1E, 80 bytes
Tôε’‚³¡× I »À Æ× †ì ³ä ‚ÚTET Öµ •¤Ÿ¯ Ù¤¥Š’#sSèDg©N+i'«ßšëć'X®×':«ìš„š‡‡×#N_èš]u»
Try it online or verify all test cases.
Explanation:
Tô # Split the (implicit) input into parts of size 10
ε # Map over each part:
’‚³¡× I »À Æ× †ì ³ä ‚ÚTET Öµ •¤Ÿ¯ Ù¤¥Š’
# Push dictionary string "numberzero I bi tri four fifth sexTET seventh inteight digitnine"
# # Split it on spaces
s # Swap so the current part is at the top of the stack again
S # Convert it to a list of digits
è # (0-based) index each digit into the string-list
D # Duplicate this list
g # Pop and push its length
© # Store this in variable `®` (without popping)
N+ # Pop and add the (0-based) map-index
i # If this length+index equals 1:
'«ßš '# Prepend dictionary string "push" to the list
ë # Else:
ć # Extract head; push remainder-list and first item
'X®× '# Push a string of `®` amount of "X"
':« '# Append ":" to it
ì # Prepend it to the extracted first item
š # Prepend this modified head back to the list
„š‡‡× # Push dictionary string "continued put"
# # Split it on the space
N_ # Check if the map-index is 0 (1 if N=0; 0 otherwise)
è # Use that to index into pair ["continued","put"]
š # Prepend this to the list as well
] # Close both the if-else statement and map
u # Uppercase every inner-most string
» # Join each inner list by spaces,
# and then each string by newlines
# (after which the result is output implicitly)
See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ’‚³¡× I »À Æ× †ì ³ä ‚ÚTET Öµ •¤Ÿ¯ Ù¤¥Š’ is "numberzero I bi tri four fifth sexTET seventh inteight digitnine"; '«ß is "push"; and „š‡‡× is "continued put".
GolfScript, 131 bytes
10/{[.,"X"*":"@1/{~"NUMBERZERO
I
BI
TRI
FOUR
FIFTH
SEXTET
SEVENTH
INTEIGHT
DIGITNINE"n/=" "}/]}%"
CONTINUED "*"PUT "\+"T X:"/"SH "*
I tried several different approaches only to get the same byte count.
Jelly, 77 bytes
<©⁵ị“¡Y#“¡Y5»ɓDị“œ©§ƇjɓƲƈ1çı8Sėẓ7Ėı⁹Ẇ5\^LıỵBṘƘṇ»Ḳ¤s⁵”X€⁾ :jḢ®¡Ʋ;KƊ€j“€=⁻⁴»ṭŒu
A monadic Link that accepts a non-negative integer and yields a list of characters, or a full program that prints to stdout.
How?
<©⁵ị“...»ɓDị“...»Ḳ¤s⁵”X€⁾ :jḢ®¡Ʋ;KƊ€j“...»ṭŒu - Link: non-negative integer, N
< ⁵ - {N} less than 10?
© - ...copy that to the register
ị“...» - 1-index into ["put","push"]
ɓ - use {that} as the right argument
D - decimal digits of {N}
ị“...»Ḳ¤ - 1-index into ["i","bi","tri",...,"numberzero"]
s⁵ - split {that} into chunks of ten
Ɗ€ - for each {WordList in that}:
Ʋ - last four links as a monad:
”X€ - 'X' for each
⁾ : - " :"
j - join {" :"} with {Xs}
Ḣ®¡ - head if register -> PrefixText
(i.e. if N<10 get just the leading space)
K - join {WordList} with spaces -> SeparatedWords
; - {Prefix Text} concatenate {SeparatedWords}
j“...» - join {these} with "\nCONTINUED"
ṭ - tack to {"push" or "put"}
Œu - convert to uppercase
An attempt at putting all of the character data into a single dictionary string split on spaces (“...»Ḳ¤) ended up at five more bytes :o
Japt -R, 95 93 bytes
Quiet day behind the bar today, so I've been tapping away at this for a couple of hours while I work. I'm sure there must still be plenty of room for improvement, though.
òA ˬ˰g`num¼rzoaiabiÂqafÆè¦8(xÈ´äaÄigË%igÍÂ`qaÃviUÅ©':iDçx¹iUÅ?`p© Öu`¸gEÎ:`p«h` ¸u
òA ˬ˰g`...`qaÃviUÅ©':iDçx¹iUÅ?`...`¸gEÎ:`p«h` ¸u :Implicit input of string U
ò :Partitions of length
A : 10
Ë :Map each D at 0-based index E
¬ : Split D
Ë : Map
° : Postfix increment (to coerce to an integer)
g : 0-based index into
`...` : Compressed string "numberzeroaiabiatriafourafifthasextetaseventhainteightadigitnine"
qa : Split on "a"
à : End map
v : Modify first element
i : Prepend
UÅ : Slice first character off U (empty string is falsey)
© : Logical AND with
':i : Prepend to ":"
Dçx : Fill D with "x"
¹ : End modify
i : Prepend
UÅ : Slice first character off U
? : If truthy
`...` : Compressed string "put continued"
¸ : Split on spaces
g : Get element at index
EÎ : Sign of E
: : Else
`p«h` : Compressed string "push"
¸ : Join with spaces
u : Uppercase
:Implicit output joined with newlines
Uiua, 142 bytes
≡&p⨬≡$"PUSH _"(⍚$"_ _:_"⍚⨬"PUT""CONTINUED"±°⊏⊕°◇°⊃≡⋅@X/$"_ _"⌊÷10°⊏)>1⊸⧻˜⊏⊜□⊚⇡11"IBITRIFOURFIFTHSEXTETSEVENTHINTEIGHTDIGITNINENUMBERZERO"◿10-1
Try it: Uiua pad
Explanation:
◿10-1
Subtract one from each digit and take them modulo ten, so 1 becomes zero and 0 becomes ten. This is because the digit string is broken up by the lengths of the digits, and NUMBERZERO is last, not first.
˜⊏⊜□⊚⇡11"IBITRIFOURFIFTHSEXTETSEVENTHINTEIGHTDIGITNINENUMBERZERO"
The string is partitioned into 10 sections of lengths increasing from one to ten, and the input is indexed into this list.
⨬≡$"PUSH _"(...)>1⊸⧻
If the list has only one item, prepend "PUSH ". Otherwise:
-
⊕(...)⌊÷10°⊏Group the string into sections based on each number's index floor-divided by ten. This gives sections of at most length ten.
°◇°⊃≡⋅@X/$"_ _"To each group of strings, make a string of that length by replacing each string with an X, and also give that group joined on spaces.
⍚⨬"PUT""CONTINUED"±°⊏Make another list of the same length, where the first item is
"PUT"and all others are"CO TINUED".⍚$"_ _:_"To each item of these three lists (the PUT-CONTINUED list, the X-strings list, and the lines of numbers list), join them together by this format string where each underscore is replaced by an item from the corresponding list.
≡&p
Print each line to STDOUT.
JavaScript (Node.js), 200 bytes
x=>g((x[1]?'PUT X:':'PUSH ')+[...x].map(c=>'NUMBERZERO I BI TRI FOUR FIFTH SEXTET SEVENTH INTEIGHT DIGITNINE'.split` `[c]).join`
CONTINUED X:`)
g=x=>x<(x=x.replace(/ (X{1,9}:.+)\n.*:/,' X$1 '))?g(x):x
Generate an inefficient expression and optimize
Maybe a direct way is shorter though
Charcoal, 89 bytes
E⪪θχ⁺⎇⊖Lθ⁺⎇κCONTINUED¦PUT⪫ :⭆ιX¦PUSH ⪫Eι§⪪”&↖↥↘σKjJ\AZ﹪HG⊗⮌⪫⁴ε⎇J0 H;✳﹪}✳ÞF$\`↷a¬MFι⁻V” Iλ
Try it online! Link is to verbose version of code. Explanation:
E⪪θχ⁺
Split the input after every 10 characters and loop over each substring, concatenating...
⎇⊖Lθ⁺⎇κCONTINUED¦PUT⪫ :⭆ιX¦PUSH
... the string PUSH if the input string's length was 1, otherwise the string PUT for the first substring or CONTINUED for subsequent substrings concatenated with an X repeated for each digit and then wrapped in :, with...
⪫Eι§⪪”...” Iλ
... the translation of each digit into its mnemonic (taken from a compressed string split on spaces) joined on spaces.
Retina 0.8.2, 151 bytes
M!`.{1,10}
.+
PUT $.&$*X:$&
^PUT X:
PUSH
¶PUT
¶CONTINUED
\B\d
$&
1
I
2
BI
3
TRI
4
FOUR
5
FIFTH
6
SEXTET
7
SEVENTH
8
INTEIGHT
9
DIGITNINE
0
NUMBERZERO
Try it online! Link includes test cases. Explanation:
M!`.{1,10}
Split the input into substrings of up to 10 digits.
.+
PUT $.&$*X:$&
Assume 2-10 digits.
^PUT X:
PUSH
If the number only has 1 digit, then use PUSH.
¶PUT
¶CONTINUED
If the number has more than 10 digits, then use CONTINUED for subsequent lines.
\B\d
$&
Insert spaces between the digits.
1
I
2
BI
3
TRI
4
FOUR
5
FIFTH
6
SEXTET
7
SEVENTH
8
INTEIGHT
9
DIGITNINE
0
NUMBERZERO
Convert the digits to their mnemonic form.