[number-speller] added files

This commit is contained in:
dogeystamp 2024-03-23 17:02:33 -04:00
parent 7cc175e353
commit 571c5ec85e
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
2 changed files with 141 additions and 0 deletions

12
number-speller/README.md Normal file
View File

@ -0,0 +1,12 @@
# number speller
spells huge numbers (naively)
if you want huger numbers, have a look at this https://lcn2.github.io/mersenne-english-name/tenpower/tenpower.html
example:
```
83306029999439502888147660318024101128188039133331515498036203165620671207144956939734897706481569590382876950528
eighty three sextrigintillion three hundred six quintrigintillion twenty nine quattuortrigintillion nine hundred ninety nine tretrigintillion four hundred thirty nine duotrigintillion five hundred two untrigintillion eight hundred eighty eight trigintillion one hundred fourty seven novemvigintillion six hundred sixty octovigintillion three hundred eighteen septenvigintillion twenty four sexvigintillion one hundred one quinvigintillion one hundred twenty eight quattuorvigintillion one hundred eighty eight trevigintillion thirty nine duovigintillion one hundred thirty three unvigintillion three hundred thirty one vigintillion five hundred fifteen novemdecillion four hundred ninety eight octodecillion thirty six septendecillion two hundred three sexdecillion one hundred sixty five quindecillion six hundred twenty quattuordecillion six hundred seventy one tredecillion two hundred seven duodecillion one hundred fourty four undecillion nine hundred fifty six decillion nine hundred thirty nine nonillion seven hundred thirty four octillion eight hundred ninety seven septillion seven hundred six sextillion four hundred eighty one quintillion five hundred sixty nine quadrillion five hundred ninety trillion three hundred eighty two billion eight hundred seventy six million nine hundred fifty thousand five hundred twenty eight
```

View File

@ -0,0 +1,129 @@
import math
pows = """
thousand
million
billion
trillion
quadrillion
quintillion
sextillion
septillion
octillion
nonillion
decillion
undecillion
duodecillion
tredecillion
quattuordecillion
quindecillion
sexdecillion
septendecillion
octodecillion
novemdecillion
vigintillion
unvigintillion
duovigintillion
trevigintillion
quattuorvigintillion
quinvigintillion
sexvigintillion
septenvigintillion
octovigintillion
novemvigintillion
trigintillion
untrigintillion
duotrigintillion
tretrigintillion
quattuortrigintillion
quintrigintillion
sextrigintillion
septentrigintillion
octatrigintillion
novemtrigintillion
quadragintillion
""".split()
nums = """
zero
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
""".split()
tens = """
ten
twenty
thirty
fourty
fifty
sixty
seventy
eighty
ninety
""".split()
def fmt_unit(x: int, single=False) -> list[str]:
if x == 0 and not single:
return []
return [nums[x]]
def fmt_tens(x: int) -> list[str]:
ans: list[str] = []
if x >= 20:
ans.append(tens[x // 10 - 1])
x -= (x // 10) * 10
if x > 0:
ans += fmt_unit(x)
else:
ans += fmt_unit(x)
return ans
def fmt_hundreds(x: int) -> list[str]:
ans: list[str] = []
if x < 100:
ans = fmt_tens(x)
else:
ans += fmt_unit(x // 100)
ans += ["hundred"]
x -= (x // 100) * 100
ans += fmt_tens(x)
return ans
def fmt_num(x: int) -> list[str]:
ans: list[str] = []
p: int = math.ceil(math.log10(x) // 3) * 3
while p >= 3:
val = x // (10**p)
if val > 0:
ans += fmt_hundreds(val)
ans += [pows[p // 3 - 1]]
x -= val * 10**p
p -= 3
ans += fmt_hundreds(x)
return ans
i = int(input())
print(" ".join(fmt_num(i)))