Create a gist now

Instantly share code, notes, and snippets.

@pawlos /advent_of_code_d6.py Secret
Last active Dec 24, 2017

What would you like to do?
Solution to Day 6: Memory Reallocation - part 1
#aoc_6.py
inp=[4, 10, 4, 1, 8, 4, 9, 14, 5, 1, 14, 15, 0, 15, 3, 5]
seen = []
cycles = 0
print inp
while True:
pattern = ','.join([str(i) for i in inp])
if pattern in seen:
print cycles
break
cycles +=1
seen.append(pattern)
maximum = max(inp)
max_index = inp.index(maximum)
inp[max_index] = 0
for i in range(maximum):
inp[(i+max_index+1)%len(inp)] += 1
print inp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment