Skip to content

Instantly share code, notes, and snippets.

@kaecy
Created May 20, 2022 00:30
Show Gist options
  • Save kaecy/2e3e4294d1d99c89079f0c85c3160b32 to your computer and use it in GitHub Desktop.
Save kaecy/2e3e4294d1d99c89079f0c85c3160b32 to your computer and use it in GitHub Desktop.
KN = ["", chr(19968), chr(20108), chr(19977), chr(22235), chr(20116), chr(20845), chr(19971),
chr(20843), chr(20061), chr(21313)]
TEN = chr(21313)
HUNDRED = chr(30334)
THOUSAND = chr(21315)
def split3(array):
groups = []
odd = len(array) % 3
if odd > 0:
groups.append(array[0: odd])
array = array[odd:]
for i in range(0, len(array), 3):
groups.append(array[i: i+3])
return groups
def convertSubNumToKanji(numbers):
markers = ("", TEN, HUNDRED)
numbers.reverse()
out = ""
for i in range(len(numbers)):
if i == 1 and numbers[1] == 1:
out = TEN + out; continue
if numbers[i] == 0:
continue
out = KN[ numbers[i]] + markers[i] + out
return out
def convertNumToKanji(number):
markers = (THOUSAND, "")
groups = split3(list(map(lambda i: int(i), str(number))))
out = ""
for i in range(len(groups)):
out = convertSubNumToKanji(groups[i]) + markers[i] + out
return out
print(convertNumToKanji(200000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment