1
0
www.mikescher.com/www/statics/aoc/2017/10_solution-2.py

46 lines
957 B
Python
Raw Permalink Normal View History

2020-12-14 14:03:27 +01:00
#!/usr/bin/env python3
import aoc
def twist(nums: list, nstart: int, nlen: int):
sublist = list()
for i in range(0, nlen):
sublist.append(nums[(i+nstart) % len(nums)])
for i in range(0, nlen):
nums[(i+nstart) % len(nums)] = sublist[nlen-i-1]
rawinput = aoc.read_input(10).strip()
inputlengths = list(map(lambda x: ord(x), rawinput))
inputlengths.append(17)
inputlengths.append(31)
inputlengths.append(73)
inputlengths.append(47)
inputlengths.append(23)
numberslist = list(range(0, 256))
currpos = 0
skipsize = 0
for iround in range(0,64):
for ilen in inputlengths:
twist(numberslist, currpos, ilen)
currpos = (currpos + ilen + skipsize) % len(numberslist)
skipsize += 1
densehash = list()
for i1 in range(0, 16):
xor = 0
for i2 in range(0, 16):
xor = xor ^ numberslist[i1*16 + i2]
densehash.append(xor)
hex = "".join(map(lambda n: "%0.2x" % n, densehash))
print(hex)