+/AoC

advent of code

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

Joseph RyanStart 2018!38c0746

master
906 B34 linesraw
1with open("input.txt") as f:
2    raw = f.read().strip()
3    inputs = map(int, raw.split(','))
4
5length = 256
6knot = range(length)
7skip = 0
8current = 0
9
10for i in inputs:
11    for j in range(i // 2):
12        front = (current + j) % length
13        back = (current + i - j - 1) % length
14        knot[front], knot[back] = knot[back], knot[front]
15    current += i + skip
16    skip += 1
17
18print "Part 1:", knot[0] * knot[1]
19
20knot = range(length)
21skip = 0
22current = 0
23for n in range(64):
24    for i in map(ord, raw) + [17, 31, 73, 47, 23]:
25        for j in range(i // 2):
26            front = (current + j) % length
27            back = (current + i - j - 1) % length
28            knot[front], knot[back] = knot[back], knot[front]
29        current += i + skip
30        skip += 1
31
32dense = [reduce(lambda x, y: x ^ y, knot[i * 16:(i + 1) * 16]) for i in range(16)]
33
34print "Part 2:", ''.join(hex(i)[2:].zfill(2) for i in dense)