Skip to content

Instantly share code, notes, and snippets.

@pawlos
Last active December 20, 2017 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawlos/863ced736a22b43d477bf489b181bb42 to your computer and use it in GitHub Desktop.
Save pawlos/863ced736a22b43d477bf489b181bb42 to your computer and use it in GitHub Desktop.
Solution to Day 10: Knot Hash - Part 2
#aoc_d10.py
inp = range(0,256)
org_len = [ord(c) for c in '199,0,255,136,174,254,227,16,51,85,1,2,22,17,7,192']
ind = 0
skip_size = 0
for i in range(0,64):
lengths = org_len
add = [17, 31, 73, 47, 23]
lengths = lengths + add
print lengths
for l in lengths:
w = []
for i in range(ind,ind+l):
w.append(inp[i%len(inp)])
rev = w[::-1]
o = {}
for i in range(ind,ind+l):
o[i%len(inp)] = rev[i-ind]
n = [None]*len(inp)
for i in range(0,len(inp)):
if i in o:
n[i]= o[i]
else:
n[i] = inp[i]
inp = n
ind = (ind + (l + skip_size)) % len(inp)
skip_size += 1
print 'w=',inp
res = ''
for i in range(0,16):
w = inp[i*16:(i+1)*16]
z = w[0]
for r in range(1,len(w)):
z = z ^ w[r]
res += '{:02x}'.format(z)
print res, len(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment