Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Solution to Day 10: Knot Hash
#aoc_d10.py
inp = range(0,256)#[0, 1, 2, 3, 4]
lengths = [199,0,255,136,174,254,227,16,51,85,1,2,22,17,7,192]#[3, 4, 1, 5]
ind = 0
skip_size = 0
print inp
for l in lengths:
#print 'ind:',ind,'len:',l, 'ss:',skip_size
w = []
for i in range(ind,ind+l):
#print 'app',inp[i%len(inp)]
w.append(inp[i%len(inp)])
#print 'w',w
rev = w[::-1]
o = {}
for i in range(ind,ind+l):
o[i%len(inp)] = rev[i-ind]
n = [None]*len(inp)
#print rev,o
for i in range(0,len(inp)):
if i in o:
#print 'in',i
n[i]= o[i]
else:
#print 'out',i
n[i] = inp[i]
inp = n
#print inp
#if l + skip_size < len(inp):
ind = (ind + (l + skip_size)) % len(inp)
skip_size += 1
#print 'ind',ind
#print '---------'
#print w,rev,inp
print 'w=',inp
print 'mul',inp[0]*inp[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment