Compare commits
2 Commits
863ddcaaac
...
4cdfbd93a2
Author | SHA1 | Date | |
---|---|---|---|
4cdfbd93a2 | |||
d479365a94 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__
|
5
hanzi-flash/README.md
Normal file
5
hanzi-flash/README.md
Normal 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.
|
25
hanzi-flash/hanzi_flash.py
Normal file
25
hanzi-flash/hanzi_flash.py
Normal 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]})"])
|
@ -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
6
number-speller/caser.py
Normal 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;")
|
@ -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)))
|
Loading…
Reference in New Issue
Block a user