Compare commits

...

2 Commits

Author SHA1 Message Date
4cdfbd93a2
[hanzi-flash] added 2024-06-06 15:19:50 -04:00
d479365a94
[number-speller] fixes
- if name == main added
- problematic filename for imports changed
- added caser.py
2024-05-23 19:22:02 -04:00
6 changed files with 46 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__

5
hanzi-flash/README.md Normal file
View File

@ -0,0 +1,5 @@
# hanzi-flash
Generate flashcards for a range of frequent hanzi characters.
You need the [hanziDB CSV](https://github.com/ruddfawcett/hanziDB.csv) file for this to work.

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
"""
Generate flashcards for a range of frequent hanzi characters.
Based on https://github.com/ruddfawcett/hanziDB.csv
"""
import csv
import itertools
import argparse
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--start", default=0, type=int)
parser.add_argument("-e", "--end", default=99999999, type=int)
parser.add_argument("-O", "--output", default="hanzi_flash.csv", type=Path)
parser.add_argument("-i", "--input", default="hanzi_db.csv", type=Path)
args = parser.parse_args()
with open(args.input) as csv_file:
reader = csv.reader(csv_file)
with open(args.output, "w") as outp_file:
writer = csv.writer(outp_file)
for row in itertools.islice(reader, args.start, args.end + 1):
writer.writerow([row[1], f"{row[2]} ({row[3]})"])

View File

@ -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

6
number-speller/caser.py Normal file
View File

@ -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;")

View File

@ -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)))