Interpret numbers very literally
Python 2, 76 bytes
f=lambda n,k=1000:n>19and(f(n/k,k/10)+`k-k%4*5`)*(n>=k)+f(n%k,k/10)or`n`[:n]
Try it online!
Test suite from Chas Brown.
A fully recursive solution that splits on place values k=1000
, k=100
, and k=10
. The separator for the place values is computed as k-k%4*5
, which maps
1000 -> 1000
100 -> 100
10 -> 0
By stopping when n<=19
, we avoid one-word numbers in the teens being split up.
Gaia, 44 43 bytes
:(!>
ℍZ:₸Z¤1>∧'0פṙ$×:dẏ×,↑ℍṙ×
@3eZ,↑¦↓3eṙ×
Longer than my original answer, but it works now.
fixed my code again but now it's twice as sad
Try it online!
@3eZ,↑¦↓3eṙ× Main function.
@3eZ Input divmod 1000, pushes input div 1000 then input mod 1000
, Pair those two value into a list
↑¦ Run the upper function on both
↓ Call the function below (loops to top function)
3eṙ The string "1000"
× Join the list with "1000"
ℍZ:₸Z¤1>∧'0פṙ$×:dẏ×,↑ℍṙ× Helper function. Called with 1 argument.
ℍZ Divmod with 100
:₸Z Copy the mod part and divmod with 10
Stack is: [100s digit, arg mod 100, 10s digit, 1s digit]
¤1> Bring 10s digit to the top and check if it's greater than 1
∧ Logical AND with 1s digit. (results in 0 or 1)
'0× Multiply the character 0 by that result
¤ Bring 'arg mod 100' to the top
ṙ$ Get its string representation and split it into characters
(simply doing digit list doesn't work in the case it's 0)
× Join this with the multiplied '0' string
:d Copy and parse as a number
ẏ Is it positive? (0 or 1)
× Multiply the string of the number by that result.
, Pair: gives the list [100s digit, string from above]
↑ Call the function above
> Remove the first ^ elements from the pair
ℍṙ× Join the resulting list with the string "100"
:(!> Helper function 2. In this program it is only called with a list.
:( Copy and get the first element.
! Boolean negate (0 or 1)
> Remove that many characters from the start of the list
Python 3+inflect, 193 bytes
import inflect,re
exec("for i in re.sub('(and)|\W',' ',%sinput())).split():\n for j in range(0,6**8):\n if i in %sj):\n print(j,end='')\n break"%(('inflect.engine().number_to_words(',)*2))
Try it online!
Very naive solution which uses Python's inflect
library. Here is the unfurled code:
import inflect,re
for i in re.sub('(and)|\W+',' ',inflect.engine().number_to_words(input())).split():
for j in range(0,6**8):
if i in inflect.engine().number_to_words(j):
print(j,end='')
break