+/AoC
advent of code
git clone https://git.julia.blue/+/AoC
0579d0a
master
1trans = "=-012" 2 3 4def to_dec (snafu ): 5places = tuple (trans .index (c )- 2 for c in snafu ) 6place = 1 7total = 0 8for n in places [::- 1 ]: 9total += place * n 10place *= 5 11return total 12 13 14def to_snafu (dec ): 15places = [] 16while dec > 0 : 17tmp = dec % 5 18places .append ((tmp + 2 )% 5 ) 19if tmp > 2 : 20dec += 5 21dec //= 5 22return "" .join (trans [i ]for i in places [::- 1 ]) 23 24 25total = 0 26for line in open ("input" ): 27total += to_dec (line .strip ()) 28 29total ,to_snafu (total ))