diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/number-speller/README.md b/number-speller/README.md index 8df796a..e19a1cf 100644 --- a/number-speller/README.md +++ b/number-speller/README.md @@ -10,3 +10,5 @@ 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 ``` + +`caser.py` is a joke thing for generating code that violates the DRY principle diff --git a/number-speller/caser.py b/number-speller/caser.py new file mode 100644 index 0000000..19c97ab --- /dev/null +++ b/number-speller/caser.py @@ -0,0 +1,6 @@ +from number_speller import fmt_num + +for i in range(int(3e5)): + print(f"\tcase {i}:") + print(f'\t\tprintf("{' '.join(fmt_num(i))}");') + print(f"\t\tbreak;") diff --git a/number-speller/number-speller.py b/number-speller/number_speller.py similarity index 93% rename from number-speller/number-speller.py rename to number-speller/number_speller.py index 9eebca9..589747d 100644 --- a/number-speller/number-speller.py +++ b/number-speller/number_speller.py @@ -113,6 +113,10 @@ def fmt_hundreds(x: int) -> list[str]: def fmt_num(x: int) -> list[str]: ans: list[str] = [] + + if x == 0: + return ["zero"] + p: int = math.ceil(math.log10(x) // 3) * 3 while p >= 3: val = x // (10**p) @@ -125,5 +129,6 @@ def fmt_num(x: int) -> list[str]: return ans -i = int(input()) -print(" ".join(fmt_num(i))) +if __name__ == "__main__": + i = int(input()) + print(" ".join(fmt_num(i)))