Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Convert integer to English

Python 3, 596 589 585 482 468 467 429 bytes def f(x): s="";i="r fif six seven eigh nine";a=f"zero one two three four five six seven eight nine ten eleven twelve thir fou{i} twen thir fo{i}".sp...

posted 3y ago by General Sebast1an‭  ·  edited 3y ago by General Sebast1an‭

Answer
#10: Post edited by user avatar General Sebast1an‭ · 2021-10-03T02:55:51Z (about 3 years ago)
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> <s>482</s> <s>468</s> <s>467</s> 429 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";i="r fif six seven eigh nine";a=f"zero one two three four five six seven eight nine ten eleven twelve thir fou{i} twen thir fo{i}".split();t=1000;c=t*t
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s&gt;"")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not(x&lt;1)*s)+"teen"*(x&gt;12)or s+a[x//10+18]+"ty"+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku9vvjoe]
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939). Golfed another 14 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4644#comment-13941). Golfed 38 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4672#comment-14000).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku9vvjoe]: https://tio.run/##lZTbitswEIavracQgS6SkwVbPiR2IsNCXSg0obCXy7LkIJOAIwcfKCXNs6c62Isd4YvNxeDJ55l/RjPW5W99LLh3vx9YBreI4xhYpwzylUfiktVNySEHFqMOsP4cTzmDPKHEtpkd@jGbUhdYmfKXOeVPKHt28XJDEU8Shp88d7mmmylCxM4pFen5AW6@EVyUUPyTZHiZUjZ1leCaUqGYiowiRohpbZSuVgH@twayuh0qZXUpLZMkEG@VQkDFppQ6sShxeaZrUWteMeGlz670px7pksGzLSu9Zw3f16eCV5DCK7AmjO@LA5vEcDsT3oG13g7cgNKtWVWjLuiDb88shlVdzuCJX5q6fS6aunNkkSWrmrymn1Jvg/h3pEKxqr59lbYZLuWJC7nJ75fX1/R7DK@DyBu6atXEv2FZv46W7gS3vXcZfrz8/PWlDDNYHYsmP8Adg9e2HJ0YyDPYbysmz@wNWKg7tBkUP0dbPHsErrYG8FxtTUC0NUDoaWsCX1sTBGMg1NgEc41NsBgD0QiYOzrhI3CJ6iPyTeCPgWAMqD6iwASqjyg0wWIMRCPAc8aAmmBkNEiCUCs9AOIQGUHI4wR9R82cBLIPSdrvz1ysPhgsVg8MF6sPBovVA8PF6oPBYvVB0B96H@jFWhgg8tSZmOKRr0dvgkBP2ASD4@2DuRqLoaGHLsZigFCebuAaEUTuKHHc0AS@BL4hLoanB4nBOwCZuN6760JckZ/PVawuUrvz8f0 "Python 3 – Try It Online"
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> <s>482</s> <s>468</s> <s>467</s> 429 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";i="r fif six seven eigh nine";a=f"zero one two three four five six seven eight nine ten eleven twelve thir fou{i} twen thir fo{i}".split();t=1000;c=t*t
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s&gt;"")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not(x&lt;1)*s)+"teen"*(x&gt;12)or s+a[x//10+18]+"ty"+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku9vvjoe]
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939). Golfed another 14 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4644#comment-13941). Golfed 38 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4672#comment-14000).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku9vvjoe]: https://tio.run/##XZLdbqMwEIWvk6cYjVQJQ3ZrSH82UPMiVS4iMhRL1ET2pHW36rOnY1Ju6gt7/OmcmWPB6YOHyW0vlyP10GdR1etVMIiNNeihtz0EGyHQGzkg@zKAs46wOZge/5OfYHIE/D4BD54I@umcTG/0y8WzDThdx5nyO40i48H65Pq0Xwm5Bcgd/4bTaDlTDZtSa910hnNeryRSbE1XByNxb287VSC82nG0k8Mm3phukXAdCoOAeRZaRFXMck5yefI5HNxx1l9bhjz@yNcrZ2K7283YJXh4FqNE2It1OLujp6tT0C9v7gqUvqmJJz57B/Gp0pBQKKTNPs/cxFl8KlUeJAkTOckX27JSk79q0qii/CfD@AOLDP9gojel3itRytlqdWEK3B0CBTDwrDdQbuBO9lQ9SFnJWd0nUCUsQRPY3s1oXkshxkddba@k1GWlK0G7Ze3XveSKYOXLLCPrk7eOsx4/Y93uvnAz/zfq8g0 "Python 3 – Try It Online"
#9: Post edited by user avatar General Sebast1an‭ · 2021-10-03T02:55:01Z (about 3 years ago)
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> <s>482</s> <s>468</s> <s>467</s> 429 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";i="r fif six seven eigh nine";a=f"zero one two three four five six seven eight nine ten eleven twelve thir fou{i} twen thir fo{i}".split();t=1000;c=t*t
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s&gt;"")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not(x&lt;1)*s)+"teen"*(x&gt;12)or s+a[x//10+18]+"ty"+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku9vvjoe]
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939). Golfed another 14 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4644#comment-13941). Golfed 38 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4672#comment-14000).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku9vvjoe]: https://tio.run/##XZLdbqMwEIWvk6cYjVQJQ3ZrSH82UPMiVS4iMhRL1ET2pHW36rOnY1Ju6gt7/OmcmWPB6YOHyW0vlyP10GdR1etVMIiNNeihtz0EGyHQGzkg@zKAs46wOZge/5OfYHIE/D4BD54I@umcTG/0y8WzDThdx5nyO40i48H65Pq0Xwm5Bcgd/4bTaDlTDZtSa910hnNeryRSbE1XByNxb287VSC82nG0k8Mm3phukXAdCoOAeRZaRFXMck5yefI5HNxx1l9bhjz@yNcrZ2K7283YJXh4FqNE2It1OLujp6tT0C9v7gqUvqmJJz57B/Gp0pBQKKTNPs/cxFl8KlUeJAkTOckX27JSk79q0qii/CfD@AOLDP9gojel3itRytlqdWEK3B0CBTDwrDdQbuBO9lQ9SFnJWd0nUCUsQRPY3s1oXkshxkddba@k1GWlK0G7Ze3XveSKYOXLLCPrk7eOsx4/Y93uvnAz/zfq8g0 "Python 3 – Try It Online"
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> <s>482</s> <s>468</s> <s>467</s> 429 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";i="r fif six seven eigh nine";a=f"zero one two three four five six seven eight nine ten eleven twelve thir fou{i} twen thir fo{i}".split();t=1000;c=t*t
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s&gt;"")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not(x&lt;1)*s)+"teen"*(x&gt;12)or s+a[x//10+18]+"ty"+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku9vvjoe]
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939). Golfed another 14 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4644#comment-13941). Golfed 38 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4672#comment-14000).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku9vvjoe]: https://tio.run/##lZTbitswEIavracQgS6SkwVbPiR2IsNCXSg0obCXy7LkIJOAIwcfKCXNs6c62Isd4YvNxeDJ55l/RjPW5W99LLh3vx9YBreI4xhYpwzylUfiktVNySEHFqMOsP4cTzmDPKHEtpkd@jGbUhdYmfKXOeVPKHt28XJDEU8Shp88d7mmmylCxM4pFen5AW6@EVyUUPyTZHiZUjZ1leCaUqGYiowiRohpbZSuVgH@twayuh0qZXUpLZMkEG@VQkDFppQ6sShxeaZrUWteMeGlz670px7pksGzLSu9Zw3f16eCV5DCK7AmjO@LA5vEcDsT3oG13g7cgNKtWVWjLuiDb88shlVdzuCJX5q6fS6aunNkkSWrmrymn1Jvg/h3pEKxqr59lbYZLuWJC7nJ75fX1/R7DK@DyBu6atXEv2FZv46W7gS3vXcZfrz8/PWlDDNYHYsmP8Adg9e2HJ0YyDPYbysmz@wNWKg7tBkUP0dbPHsErrYG8FxtTUC0NUDoaWsCX1sTBGMg1NgEc41NsBgD0QiYOzrhI3CJ6iPyTeCPgWAMqD6iwASqjyg0wWIMRCPAc8aAmmBkNEiCUCs9AOIQGUHI4wR9R82cBLIPSdrvz1ysPhgsVg8MF6sPBovVA8PF6oPBYvVB0B96H@jFWhgg8tSZmOKRr0dvgkBP2ASD4@2DuRqLoaGHLsZigFCebuAaEUTuKHHc0AS@BL4hLoanB4nBOwCZuN6760JckZ/PVawuUrvz8f0 "Python 3 – Try It Online"
#8: Post edited by user avatar General Sebast1an‭ · 2021-10-02T14:22:42Z (about 3 years ago)
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> <s>482</s> <s>468</s> 467 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a="zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty thirty forty fifty sixty seventy eighty ninety".split();t=1000;c=t*t
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s&gt;"")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not(x&lt;1)*s)or s+a[x//10+18]+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku8b0ee9]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939). Golfed another 14 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4644#comment-13941).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku8b0ee9]: https://tio.run/##XZJRb9sgFIWfk19xhVTJ2NmKna5dnOI/UvkhcnCN5OEIblq8ab89uxeal/EAh0/nHGPjy4rT4va329mMMBZRtttN0EIcT1r8Nn6BxRnAzwVw8sbAuFw9jPbDQLARgvkwDox9nxCcZSNv50Tx08xkw8l6NLTnZBZ2TCsV5JXtSaUiFtyVBJU4XHPJShVppvya0utXds3JNedW8T1cZouFPKKulVLHQWOJ240dIXZ6aIOm93x8HGQl4JedZ7s4cYwPerhbsA2VFiDKInRCyCrZke30ra7h5M7JnytDGb/s243TsTscEnYMT28UpCP0FJ2u7uxNThL6L1u6SlAvl3iDV@8gvjYKGIWKavqycAsW8bWWZZCLz5TLq/pnXxXim2DwUKtelgWvnZI3NAGHUzABNLypHdQ7eKKZ1TPJhtbmB4OGMZ2Kwf4poTTugoIvqtlnUqu6UQ2hw330W7oaiGDpxu6PbC/eOixG8Se23eGv2KW/S97@AQ "Python 3 – Try It Online"
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> <s>482</s> <s>468</s> <s>467</s> 429 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";i="r fif six seven eigh nine";a=f"zero one two three four five six seven eight nine ten eleven twelve thir fou{i} twen thir fo{i}".split();t=1000;c=t*t
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s&gt;"")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not(x&lt;1)*s)+"teen"*(x&gt;12)or s+a[x//10+18]+"ty"+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku9vvjoe]
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939). Golfed another 14 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4644#comment-13941). Golfed 38 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4672#comment-14000).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku9vvjoe]: https://tio.run/##XZLdbqMwEIWvk6cYjVQJQ3ZrSH82UPMiVS4iMhRL1ET2pHW36rOnY1Ju6gt7/OmcmWPB6YOHyW0vlyP10GdR1etVMIiNNeihtz0EGyHQGzkg@zKAs46wOZge/5OfYHIE/D4BD54I@umcTG/0y8WzDThdx5nyO40i48H65Pq0Xwm5Bcgd/4bTaDlTDZtSa910hnNeryRSbE1XByNxb287VSC82nG0k8Mm3phukXAdCoOAeRZaRFXMck5yefI5HNxx1l9bhjz@yNcrZ2K7283YJXh4FqNE2It1OLujp6tT0C9v7gqUvqmJJz57B/Gp0pBQKKTNPs/cxFl8KlUeJAkTOckX27JSk79q0qii/CfD@AOLDP9gojel3itRytlqdWEK3B0CBTDwrDdQbuBO9lQ9SFnJWd0nUCUsQRPY3s1oXkshxkddba@k1GWlK0G7Ze3XveSKYOXLLCPrk7eOsx4/Y93uvnAz/zfq8g0 "Python 3 – Try It Online"
#7: Post edited by user avatar General Sebast1an‭ · 2021-10-01T11:51:21Z (about 3 years ago)
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> <s>482</s> 468 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a="zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty thirty forty fifty sixty seventy eighty ninety".split();t=1000;c=t*t
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s&gt;"")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not s*(x&lt;1))or s+a[x//10+18]+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku6j30po]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939). Golfed another 14 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4644#comment-13941).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku6j30po]: https://tio.run/##XZJfb4MgFMWf209xQ9JEtNvQdn9qh19k8aGxOEkcNnDb4ZZ99u4C68t4gMMv5xxRPM04TGZzvR5VD33meb1cOMnY/iDZl7ITTEYBfk6Ag1UK@ulsodcXBU57cOqiDCj9PiAYHYxhO0aKn2okGw7aoqJ9SCah@7hSQVqDPapYFEToioJKDM6pZKaKOFN@jun5Lzun5JxyM7t3p1FjxvcoSyHEvpOY43Khe/CN7Gon6T0fHjpeMPjQ46gnw/Z@JbubBWtXSAYsz1zDGC@iHYOdvtXZHcwx@lOly/2ffbkw0je7XcQmwMMbBekILUWHszlalZKE/mVzUzDqDSVW4dka8K@VgIBcQTVtnpkJKZD515LzySYc2ovypS0ydscCWJWi5WSitRH8isphd3DKgYQ3sYZyDVuag3oiWdFaPQZQBUzHCmCzjSiOm6Dgs6g2iZSirERFaHcb7ZLuBjxourLbI@uT1Qaznn37utn9sHX8vfj1Fw "Python 3 – Try It Online"
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> <s>482</s> <s>468</s> 467 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a="zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty thirty forty fifty sixty seventy eighty ninety".split();t=1000;c=t*t
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s&gt;"")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not(x&lt;1)*s)or s+a[x//10+18]+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku8b0ee9]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939). Golfed another 14 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4644#comment-13941).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku8b0ee9]: https://tio.run/##XZJRb9sgFIWfk19xhVTJ2NmKna5dnOI/UvkhcnCN5OEIblq8ab89uxeal/EAh0/nHGPjy4rT4va329mMMBZRtttN0EIcT1r8Nn6BxRnAzwVw8sbAuFw9jPbDQLARgvkwDox9nxCcZSNv50Tx08xkw8l6NLTnZBZ2TCsV5JXtSaUiFtyVBJU4XHPJShVppvya0utXds3JNedW8T1cZouFPKKulVLHQWOJ240dIXZ6aIOm93x8HGQl4JedZ7s4cYwPerhbsA2VFiDKInRCyCrZke30ra7h5M7JnytDGb/s243TsTscEnYMT28UpCP0FJ2u7uxNThL6L1u6SlAvl3iDV@8gvjYKGIWKavqycAsW8bWWZZCLz5TLq/pnXxXim2DwUKtelgWvnZI3NAGHUzABNLypHdQ7eKKZ1TPJhtbmB4OGMZ2Kwf4poTTugoIvqtlnUqu6UQ2hw330W7oaiGDpxu6PbC/eOixG8Se23eGv2KW/S97@AQ "Python 3 – Try It Online"
#6: Post edited by user avatar General Sebast1an‭ · 2021-09-30T06:05:09Z (about 3 years ago)
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> 482 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a="zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split();b="twenty thirty forty fifty sixty seventy eighty ninety".split();c=10**6;t=1000
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s!="")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not s*(x&lt;1))or s+b[x//10-2]+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku6gsicd]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku6gsicd]: https://tio.run/##RZLRbsIgFIav9SnOSExKqxutbotVfJGlF1rpStJRA8dJt@zZ3YFq5IJz@PP/H5RyGrDtzfJ6PaoGmsTzcjpxkrHNXrIfZXvojQK89ICtVQqa/myh0d8KnPbg1LcyoPRni2B0MIZlF1W8qI5s2GqLitYhOTa6iZUAYw322EVQaAIrNOzZnTqNCd8cJCOgwWEEDoSLM7GGSBpunGGkDCNjeBBqmYs0fdsgVSGmE92A38m6dJK@@uWl5hmDL911ujds42eyvluwdJlkwNLEPdHF8Cz6Mfjp6s5ub44xgDHgUn/zTydG@t16HWUTxP0HBWn3iqLt2RytGpP57TyPbGoyRtwAsQrP1oDfFgKC5DLCVGlieqRA4rc5570l@TDSF0WVJWzBgm2Wi4qTh@pO8Csqh/XeKQcSPsQc8jmsaA7dG7UF1eI1CEWQ6VRBWK6iFMe9oeC7KJajkou8EAVJ6/uopvR3wIOmV3DfsjxZbTBp2K8vd@s/No@PjV//AQ "Python 3 – Try It Online"
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> <s>482</s> 468 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a="zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty thirty forty fifty sixty seventy eighty ninety".split();t=1000;c=t*t
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s&gt;"")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not s*(x&lt;1))or s+a[x//10+18]+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku6j30po]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939). Golfed another 14 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4644#comment-13941).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku6j30po]: https://tio.run/##XZJfb4MgFMWf209xQ9JEtNvQdn9qh19k8aGxOEkcNnDb4ZZ99u4C68t4gMMv5xxRPM04TGZzvR5VD33meb1cOMnY/iDZl7ITTEYBfk6Ag1UK@ulsodcXBU57cOqiDCj9PiAYHYxhO0aKn2okGw7aoqJ9SCah@7hSQVqDPapYFEToioJKDM6pZKaKOFN@jun5Lzun5JxyM7t3p1FjxvcoSyHEvpOY43Khe/CN7Gon6T0fHjpeMPjQ46gnw/Z@JbubBWtXSAYsz1zDGC@iHYOdvtXZHcwx@lOly/2ffbkw0je7XcQmwMMbBekILUWHszlalZKE/mVzUzDqDSVW4dka8K@VgIBcQTVtnpkJKZD515LzySYc2ovypS0ydscCWJWi5WSitRH8isphd3DKgYQ3sYZyDVuag3oiWdFaPQZQBUzHCmCzjSiOm6Dgs6g2iZSirERFaHcb7ZLuBjxourLbI@uT1Qaznn37utn9sHX8vfj1Fw "Python 3 – Try It Online"
#5: Post edited by user avatar General Sebast1an‭ · 2021-09-30T05:00:51Z (about 3 years ago)
  • # [Python 3], <s>596</s> <s>589</s> 585 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"];b=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];c=1000000
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=1000:
  • &#9;&#9;if s!="":s+=" "
  • &#9;&#9;s+=f(x//1000)+" thousand";x%=1000
  • &#9;m=s!="";n=x&gt;=100
  • &#9;if(x&gt;0)*m:s+=" "
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if(m|n)*(x&gt;0):
  • &#9;&#9;if n:s+=" "
  • &#9;&#9;s+="and "
  • &#9;if x&lt;20:
  • &#9;&#9;if s==""or x&gt;0:s+=a[x]
  • &#9;else:
  • &#9;&#9;s+=b[x//10-2];x%=10
  • &#9;&#9;if x&gt;0:s+="-"+a[x]
  • &#9;return s
  • </code></pre>
  • [Try it online!][TIO-ku6fdp3k]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku6fdp3k]: https://tio.run/##VZLdjsIgEIWv9SlYkk2sP7FFdzfWxRcxvehWuiVpqQHUdn@evTsDtMlywRyOnG@mxGtvq1bthuEiSlIuuiidzwyn9JjzM/0SuqVr2ioBu32gtpUWeCrbm8Yi73gyssNd3IWCKuRnZaEq6YPerMOv9iFqF7KV1FY4D2mjlGVQAB0VRoN2cC@R72R2/IBpAaxsP4J7hw0VmH0g9hOvH2n9yOqBVPAkdms@kyXpTrxIDYeH2W6LaEVJI@tatooeu2dejFcwAe@GJ/MEj5eaFaeEggPCZfEGxuGxbyZXF5dPXJeGu8xRcU9C6KI7xdGymTgAVnjIz56VAaq6qYsWE8nFmh8VLV04jKP@jUKhc8B172wamUP7VsOHxKFHNp@J2ojUpz580w3LfCufCrfphq58Qgt704qYwQpji9wIQzg5x2uSrMkedlSvIBlU9oIGQxtGR2O3d5Zbo4DgW8x23knihMUMrMO4snmJUxOpyNQyvWqp7KKk3116OvzStftPR8Mf "Python 3 – Try It Online"
  • # [Python 3], <s>596</s> <s>589</s> <s>585</s> 482 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a="zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split();b="twenty thirty forty fifty sixty seventy eighty ninety".split();c=10**6;t=1000
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=t:s+=" "*(s!="")+f(x//t)+" thousand";x%=t
  • &#9;if s*x:s+=" "
  • &#9;n=x&gt;99
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if s*x:s+=" "*n+"and "
  • &#9;return x&lt;20 and s+a[x]*(not s*(x&lt;1))or s+b[x//10-2]+("-"+a[x%10])*(x%10&gt;0)
  • </code></pre>
  • [Try it online!][TIO-ku6gsicd]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933). Golfed a massive 103 bytes thanks to [**@Moshi**](https://codegolf.codidact.com/users/53196)'s [advice](https://codegolf.codidact.com/comments/thread/4642#comment-13939).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku6gsicd]: https://tio.run/##RZLRbsIgFIav9SnOSExKqxutbotVfJGlF1rpStJRA8dJt@zZ3YFq5IJz@PP/H5RyGrDtzfJ6PaoGmsTzcjpxkrHNXrIfZXvojQK89ICtVQqa/myh0d8KnPbg1LcyoPRni2B0MIZlF1W8qI5s2GqLitYhOTa6iZUAYw322EVQaAIrNOzZnTqNCd8cJCOgwWEEDoSLM7GGSBpunGGkDCNjeBBqmYs0fdsgVSGmE92A38m6dJK@@uWl5hmDL911ujds42eyvluwdJlkwNLEPdHF8Cz6Mfjp6s5ub44xgDHgUn/zTydG@t16HWUTxP0HBWn3iqLt2RytGpP57TyPbGoyRtwAsQrP1oDfFgKC5DLCVGlieqRA4rc5570l@TDSF0WVJWzBgm2Wi4qTh@pO8Csqh/XeKQcSPsQc8jmsaA7dG7UF1eI1CEWQ6VRBWK6iFMe9oeC7KJajkou8EAVJ6/uopvR3wIOmV3DfsjxZbTBp2K8vd@s/No@PjV//AQ "Python 3 – Try It Online"
#4: Post edited by user avatar General Sebast1an‭ · 2021-09-30T04:18:15Z (about 3 years ago)
  • # [Python 3], <s>596</s> <s>589</s> 586 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"];b=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];c=1000000
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=1000:
  • &#9;&#9;if s!="":s+=" "
  • &#9;&#9;s+=f(x//1000)+" thousand";x%=1000
  • &#9;m=s!="";n=x&gt;=100
  • &#9;if(x&gt;0)*m:s+=" "
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if(m|n)*(x&gt;0):
  • &#9;&#9;if n:s+=" "
  • &#9;&#9;s+="and "
  • &#9;if x&lt;20:
  • &#9;&#9;if s==""or x&gt;0:s+=a[x]
  • &#9;else:
  • &#9;&#9;s+=b[x//10-2];x=x%10
  • &#9;&#9;if x&gt;0:s+="-"+a[x]
  • &#9;return s
  • </code></pre>
  • [Try it online!][TIO-ku6fdp3k]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku6fdp3k]: https://tio.run/##VZLdjsIgEIWv9SlYEhPrT2yruxvbxRcxvdBKtyQtNYBK9@fZ3RmgTZYL5nDkfDMlXntTd3L7fF54Raq5jbLpRDNK8xM70i@uOrqineSwmwdqUyuOp6q7KSzijictLO78ziVULj5rA1UKH/RmE341D964kKmFMtx5SBukqIIC6KAwGrSDe4l8J4v8DNMCWJp@APcOGyow@0DsR14/0PqB1QOpZEns1nQiKmIPrMw0g4fZbMpoSUkrmkZ0kuZ2xsrhCibg3fCkX@DxMr1klFBwQLgs3sA4PPZNn@TF5RPXpWUuk0vmSQid20McLdqRA2CJh9PRswpA1Td5UXwkuVj7I6OFC4dx5L9RKHQOOPuRjiMzaN8p@JA49CimE95onvnU2Tddp0VumZ0lsY@F63RNlz6iuLkpSfTTcG3Kk@aaMHKMVyRZkR3sqN5AplDTVzRStGF2NLY7Z7k1CAi@x@nWO0mcpHEK1n5YxbTCsYmQZGyZXZWQZl7Rb5sd9r905f7U0fMP "Python 3 – Try It Online"
  • # [Python 3], <s>596</s> <s>589</s> 585 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"];b=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];c=1000000
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=1000:
  • &#9;&#9;if s!="":s+=" "
  • &#9;&#9;s+=f(x//1000)+" thousand";x%=1000
  • &#9;m=s!="";n=x&gt;=100
  • &#9;if(x&gt;0)*m:s+=" "
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if(m|n)*(x&gt;0):
  • &#9;&#9;if n:s+=" "
  • &#9;&#9;s+="and "
  • &#9;if x&lt;20:
  • &#9;&#9;if s==""or x&gt;0:s+=a[x]
  • &#9;else:
  • &#9;&#9;s+=b[x//10-2];x%=10
  • &#9;&#9;if x&gt;0:s+="-"+a[x]
  • &#9;return s
  • </code></pre>
  • [Try it online!][TIO-ku6fdp3k]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku6fdp3k]: https://tio.run/##VZLdjsIgEIWv9SlYkk2sP7FFdzfWxRcxvehWuiVpqQHUdn@evTsDtMlywRyOnG@mxGtvq1bthuEiSlIuuiidzwyn9JjzM/0SuqVr2ioBu32gtpUWeCrbm8Yi73gyssNd3IWCKuRnZaEq6YPerMOv9iFqF7KV1FY4D2mjlGVQAB0VRoN2cC@R72R2/IBpAaxsP4J7hw0VmH0g9hOvH2n9yOqBVPAkdms@kyXpTrxIDYeH2W6LaEVJI@tatooeu2dejFcwAe@GJ/MEj5eaFaeEggPCZfEGxuGxbyZXF5dPXJeGu8xRcU9C6KI7xdGymTgAVnjIz56VAaq6qYsWE8nFmh8VLV04jKP@jUKhc8B172wamUP7VsOHxKFHNp@J2ojUpz580w3LfCufCrfphq58Qgt704qYwQpji9wIQzg5x2uSrMkedlSvIBlU9oIGQxtGR2O3d5Zbo4DgW8x23knihMUMrMO4snmJUxOpyNQyvWqp7KKk3116OvzStftPR8Mf "Python 3 – Try It Online"
#3: Post edited by user avatar General Sebast1an‭ · 2021-09-30T04:17:11Z (about 3 years ago)
  • # [Python 3], <s>596</s> 589 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"];b=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];c=1000000
  • &#9;if x&gt;=c:s=f(x//c)+" million";x=x%c
  • &#9;if x&gt;=1000:
  • &#9;&#9;if s!="":s+=" "
  • &#9;&#9;s+=f(x//1000)+" thousand";x=x%1000
  • &#9;m=s!="";n=x&gt;=100
  • &#9;if(x&gt;0)*m:s+=" "
  • &#9;if n:s+=a[x//100]+" hundred";x=x%100
  • &#9;if(m|n)*(x&gt;0):
  • &#9;&#9;if n:s+=" "
  • &#9;&#9;s+="and "
  • &#9;if x&lt;20:
  • &#9;&#9;if s==""or x&gt;0:s+=a[x]
  • &#9;else:
  • &#9;&#9;s+=b[x//10-2];x=x%10
  • &#9;&#9;if x&gt;0:s+="-"+a[x]
  • &#9;return s
  • </code></pre>
  • [Try it online!][TIO-ku6f3f8v]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku6f3f8v]: https://tio.run/##VZLbboMwDIavy1N4kSaVHlSg3abRpS9ScdHSMCJBmJKwwQ7P3tlJ6LRcxL9N/s8m8DbaulPb6/UiKqjmQ5xHM8MZ25/4kX0K3bEV65TA3X6QtrUWlFVdrynId8qMHGgX70JhFPK1thiV9EZfbMJT@yEaZ7K11Fa4GtEmKaugEDopsgbt4F4S38lif8ZpEazsOIFHhw0RmWMgjjfeONHGiTUiqeRp4lY0kxUMB17mhuPFbDZlvGTQyqaRnWL7gQ/35XSGLHhxlJk7vL3cLDkDhhUUzkwnyI@33ZuTunhA6vq03Jn2insUUefDIYkX7Q2EZEXJ6ehhBbLqXl20@EM5X/ut4oVzh4HUv2EY9g684SW7Dc2xf6fxVZLQpIhmojEi966z77rOitDL28JxtmZLb9HC9lqBuVphbHkywgCHIyQrSFeww53UI8oMY/ZAhYzKODwVtjtXcmsSaHxKsq2vpEmaJRmWnqcFRRThZwbVt2ehQSq4tc4jAHjTUtl5xb78gfzw/MNW@KP7NI6j6y8 "Python 3 – Try It Online"
  • # [Python 3], <s>596</s> <s>589</s> 586 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"];b=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];c=1000000
  • &#9;if x&gt;=c:s=f(x//c)+" million";x%=c
  • &#9;if x&gt;=1000:
  • &#9;&#9;if s!="":s+=" "
  • &#9;&#9;s+=f(x//1000)+" thousand";x%=1000
  • &#9;m=s!="";n=x&gt;=100
  • &#9;if(x&gt;0)*m:s+=" "
  • &#9;if n:s+=a[x//100]+" hundred";x%=100
  • &#9;if(m|n)*(x&gt;0):
  • &#9;&#9;if n:s+=" "
  • &#9;&#9;s+="and "
  • &#9;if x&lt;20:
  • &#9;&#9;if s==""or x&gt;0:s+=a[x]
  • &#9;else:
  • &#9;&#9;s+=b[x//10-2];x=x%10
  • &#9;&#9;if x&gt;0:s+="-"+a[x]
  • &#9;return s
  • </code></pre>
  • [Try it online!][TIO-ku6fdp3k]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku6fdp3k]: https://tio.run/##VZLdjsIgEIWv9SlYEhPrT2yruxvbxRcxvdBKtyQtNYBK9@fZ3RmgTZYL5nDkfDMlXntTd3L7fF54Raq5jbLpRDNK8xM70i@uOrqineSwmwdqUyuOp6q7KSzijictLO78ziVULj5rA1UKH/RmE341D964kKmFMtx5SBukqIIC6KAwGrSDe4l8J4v8DNMCWJp@APcOGyow@0DsR14/0PqB1QOpZEns1nQiKmIPrMw0g4fZbMpoSUkrmkZ0kuZ2xsrhCibg3fCkX@DxMr1klFBwQLgs3sA4PPZNn@TF5RPXpWUuk0vmSQid20McLdqRA2CJh9PRswpA1Td5UXwkuVj7I6OFC4dx5L9RKHQOOPuRjiMzaN8p@JA49CimE95onvnU2Tddp0VumZ0lsY@F63RNlz6iuLkpSfTTcG3Kk@aaMHKMVyRZkR3sqN5AplDTVzRStGF2NLY7Z7k1CAi@x@nWO0mcpHEK1n5YxbTCsYmQZGyZXZWQZl7Rb5sd9r905f7U0fMP "Python 3 – Try It Online"
#2: Post edited by user avatar General Sebast1an‭ · 2021-09-30T04:12:05Z (about 3 years ago)
  • # [Python 3], 596 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"];b=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];c=1000000
  • &#9;if x&gt;=c:s=f(x//c)+" million";x=x%c
  • &#9;if x&gt;=1000:
  • &#9;&#9;if s!="":s+=" "
  • &#9;&#9;s+=f(x//1000)+" thousand";x=x%1000
  • &#9;m=s!="";n=x&gt;=100
  • &#9;if x&gt;0 and m:s+=" "
  • &#9;if n:s+=a[x//100]+" hundred";x=x%100
  • &#9;if(m or n)and x&gt;0:
  • &#9;&#9;if n:s+=" "
  • &#9;&#9;s+="and "
  • &#9;if x&lt;20:
  • &#9;&#9;if s==""or x&gt;0:s+=a[x]
  • &#9;else:
  • &#9;&#9;s+=b[x//10-2];x=x%10
  • &#9;&#9;if x&gt;0:s+="-"+a[x]
  • &#9;return s
  • </code></pre>
  • [Try it online!][TIO-ku5ojvmu]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku5ojvmu]: https://tio.run/##VZJhb4IwEIY/y6@4NVkiUSOg2yKu@yOGD4plNIFi2qKwZb/d3bXFZf3Qvnfc@9y14TLaulOb@/0sKqjmQ5xHM8MZ2x/5gX0J3bEl65TA3d5I21oLiqqu13TIK0VGDrSLq1B4CvlZWzyV9EafbMJXexONM9laaitcjmiTlFVQCJ0UWYN2cC@J72SxP@G0CFZ2nMCjw4YTmWMgjg/eONHGiTUiqeRp4lY0kxUMH7zMDceHWa/LeMGglU0jO8X2Ax@ey6mGLPhwFJknfL3cLDgDhhkUzkwV5MfX7s1RnT0gdX1a7kx7xT0qUBPAOmgfLEwqCo4HzysQV/fqrMUfjarmLXQaVExupIS51L@ZGH30zOE9e8zOcQz0kss3KqKZaIzIvevkO6@yIvTztlDOVmzhLVrYXiswdyuMLY9GGOBwgGQJ6RK2uJN6RZnhmb1QIqM0XoASm61LuTUJNL4l2cZn0iTNkgxTu2lBEUUV3bpvT0KDVPBonUcAcNFS2XnFvn1B/rH7YUv8330Yx9H9Fw "Python 3 – Try It Online"
  • # [Python 3], <s>596</s> 589 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(x):
  • &#9;s="";a=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"];b=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];c=1000000
  • &#9;if x&gt;=c:s=f(x//c)+" million";x=x%c
  • &#9;if x&gt;=1000:
  • &#9;&#9;if s!="":s+=" "
  • &#9;&#9;s+=f(x//1000)+" thousand";x=x%1000
  • &#9;m=s!="";n=x&gt;=100
  • &#9;if(x&gt;0)*m:s+=" "
  • &#9;if n:s+=a[x//100]+" hundred";x=x%100
  • &#9;if(m|n)*(x&gt;0):
  • &#9;&#9;if n:s+=" "
  • &#9;&#9;s+="and "
  • &#9;if x&lt;20:
  • &#9;&#9;if s==""or x&gt;0:s+=a[x]
  • &#9;else:
  • &#9;&#9;s+=b[x//10-2];x=x%10
  • &#9;&#9;if x&gt;0:s+="-"+a[x]
  • &#9;return s
  • </code></pre>
  • [Try it online!][TIO-ku6f3f8v]
  • This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.
  • Golfed 7 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4639#comment-13933).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku6f3f8v]: https://tio.run/##VZLbboMwDIavy1N4kSaVHlSg3abRpS9ScdHSMCJBmJKwwQ7P3tlJ6LRcxL9N/s8m8DbaulPb6/UiKqjmQ5xHM8MZ25/4kX0K3bEV65TA3X6QtrUWlFVdrynId8qMHGgX70JhFPK1thiV9EZfbMJT@yEaZ7K11Fa4GtEmKaugEDopsgbt4F4S38lif8ZpEazsOIFHhw0RmWMgjjfeONHGiTUiqeRp4lY0kxUMB17mhuPFbDZlvGTQyqaRnWL7gQ/35XSGLHhxlJk7vL3cLDkDhhUUzkwnyI@33ZuTunhA6vq03Jn2insUUefDIYkX7Q2EZEXJ6ehhBbLqXl20@EM5X/ut4oVzh4HUv2EY9g684SW7Dc2xf6fxVZLQpIhmojEi966z77rOitDL28JxtmZLb9HC9lqBuVphbHkywgCHIyQrSFeww53UI8oMY/ZAhYzKODwVtjtXcmsSaHxKsq2vpEmaJRmWnqcFRRThZwbVt2ehQSq4tc4jAHjTUtl5xb78gfzw/MNW@KP7NI6j6y8 "Python 3 – Try It Online"
#1: Initial revision by user avatar General Sebast1an‭ · 2021-09-29T15:47:04Z (about 3 years ago)
# [Python 3], 596 bytes

<!-- language-all: lang-python -->

<pre><code>def f(x):
&#9;s="";a=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"];b=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];c=1000000
&#9;if x&gt;=c:s=f(x//c)+" million";x=x%c
&#9;if x&gt;=1000:
&#9;&#9;if s!="":s+=" "
&#9;&#9;s+=f(x//1000)+" thousand";x=x%1000
&#9;m=s!="";n=x&gt;=100
&#9;if x&gt;0 and m:s+=" "
&#9;if n:s+=a[x//100]+" hundred";x=x%100
&#9;if(m or n)and x&gt;0:
&#9;&#9;if n:s+=" "
&#9;&#9;s+="and "
&#9;if x&lt;20:
&#9;&#9;if s==""or x&gt;0:s+=a[x]
&#9;else:
&#9;&#9;s+=b[x//10-2];x=x%10
&#9;&#9;if x&gt;0:s+="-"+a[x]
&#9;return s
</code></pre>

[Try it online!][TIO-ku5ojvmu]

This solution is the biggest golf I can afford for the [original ungolfed implementation](https://tio.run/##hVTbbtswDH33V3ACCsRoijpO16LZ2h8J@pAudC1AkQtJbusN@/aUoi6xF2/Tg0VR1DkkdeTXwbWdXh@Pe2wA9YuStl3oclMADYO2Vw4eQIiCHbIBDY8PsKp4hKhJZIa4vo5BJVyCgINUSnZa5BOagjVcJKhz/BM4eSP@F5/KaWPEfEk7IIpz7x8JhWyo5t7u9H4@nZCLPeyU0v3B0s4WxE80nViC6DT6yb3zyrUGed10veFZvvHayg@e8A21N1C@tM4bWkYA759UEoZAlc64d1QBzbXSOAxez5Rt2SSTCLPpAdKCiaPtudmGJ2Z2QyyOmLQbMtMQeJJBJEOiGE4EQ4YfMvjgoRm73dnUZU8yvsBvo7uGCihiEr0p5u82wba93htk1CSWrJ7R9hxMvtNtkMMTqyGemBVDRl5MCurMmKrkGriaiWpns/m/ZIVHG7@471BPgUPjKIn07v71LkZFh2tHZXGuOySHLXBj4ArqqJFpP86S@EtdV4I6OyGOPxTXGx0Di6ND637sLAYVVktYLeGGvt66JbOmuf7qHbV303V4x/qGXTySQQfvqnodPKtqVVc1ue7T8KIkPQMl84wGpIZMzQW8GqndohG/QsDm8f43STr/OthZlsXxEw) by [**@celtschk**](https://codegolf.codidact.com/users/8056). It took quite an effort to take down hundreds of bytes. There might be more ways I can shorten this huge stack of code, but this is the best I could do for now.

[Python 3]: https://docs.python.org/3/
[TIO-ku5ojvmu]: https://tio.run/##VZJhb4IwEIY/y6@4NVkiUSOg2yKu@yOGD4plNIFi2qKwZb/d3bXFZf3Qvnfc@9y14TLaulOb@/0sKqjmQ5xHM8MZ2x/5gX0J3bEl65TA3d5I21oLiqqu13TIK0VGDrSLq1B4CvlZWzyV9EafbMJXexONM9laaitcjmiTlFVQCJ0UWYN2cC@J72SxP@G0CFZ2nMCjw4YTmWMgjg/eONHGiTUiqeRp4lY0kxUMH7zMDceHWa/LeMGglU0jO8X2Ax@ey6mGLPhwFJknfL3cLDgDhhkUzkwV5MfX7s1RnT0gdX1a7kx7xT0qUBPAOmgfLEwqCo4HzysQV/fqrMUfjarmLXQaVExupIS51L@ZGH30zOE9e8zOcQz0kss3KqKZaIzIvevkO6@yIvTztlDOVmzhLVrYXiswdyuMLY9GGOBwgGQJ6RK2uJN6RZnhmb1QIqM0XoASm61LuTUJNL4l2cZn0iTNkgxTu2lBEUUV3bpvT0KDVPBonUcAcNFS2XnFvn1B/rH7YUv8330Yx9H9Fw "Python 3 – Try It Online"