+/AoC

advent of code

git clone https://git.julia.blue/+/AoC

Joseph RyanA lot closer this year! (missing 19 and 22b)0579d0a

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