Last active
May 13, 2021 14:06
-
-
Save jack980517/7acb9d9b3674623bbc0343ce081cd66a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python2 | |
#quizknock kawamura number system: https://youtu.be/xROMDZE4U7U | |
add='-a-' | |
subtract='sk' | |
levels=['','raf','bxogg'] | |
digits_lowerhalf=['xzea','dhea','ija'] | |
digits_upperhalf=[(levels[1]+subtract+_) for _ in digits_lowerhalf[::-1]] | |
digits=['']+digits_lowerhalf+digits_upperhalf | |
def int_to_kawamura(n): | |
if not 0<n<len(digits)**len(levels): | |
raise ValueError | |
result='' | |
for i in range(len(levels)-1,-1,-1): | |
x=len(digits)**i | |
if n>=x: | |
current_digit=n/x | |
n%=x | |
result+=levels[i] | |
if current_digit!=1 or i==0: | |
if result!='' and result[-1]!='-' and current_digit>len(digits_lowerhalf): | |
result+='-' | |
result+=digits[current_digit] | |
if n!=0: | |
result+=add | |
return result | |
def kawamura_to_int(s): | |
result=0 | |
s=s.split(add) | |
for i in s: | |
level=0 | |
if i.startswith(levels[1]+subtract): | |
#upper half special case | |
#if not dealt with here, it will trigger level detection below | |
value=digits.index(i) | |
else: | |
for level in range(len(levels)-1,0,-1): | |
if i.startswith(levels[level]): | |
break | |
remainder=i.split('-')[1] if '-' in i else i[len(levels[level]):] | |
value=digits.index(remainder) | |
if value==0: | |
value=1 | |
result+=value*(len(digits)**level) | |
return result | |
#print int_to_kawamura(int(sys.argv[-1])) | |
for i in range(1,len(digits)**len(levels)): | |
assert kawamura_to_int(int_to_kawamura(i))==i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment