day 25 simplify

main
magical 2022-12-24 22:15:02 -08:00
parent 666aa2bcad
commit 5a27954c11
1 changed files with 6 additions and 13 deletions

View File

@ -8,33 +8,26 @@ def eval(num):
def tosnafu(n):
orig = n
digits = []
carry = 0
while n != 0:
n, d = divmod(n, 5)
digits.append(d)
print(digits)
carry = 0
for i in range(len(digits)):
d = digits[i] + carry
carry, d = divmod(d, 5)
carry, d = divmod(d+carry, 5)
if d > 2:
carry += 1
d -= 5
digits[i] = d
digits.append(d)
if carry:
digits.append(carry)
digits.reverse()
snafu = "".join("=-012"[d+2] for d in digits)
print(n, digits, snafu)
#print(n, digits, snafu)
assert eval(snafu) == orig
return snafu
t = 0
for line in open("input"):
n = (eval(line.strip()))
n = eval(line.strip())
print(n)
t += n