Solution to Day 6: Memory Reallocation - part 2
#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 | |
print len(seen)-seen.index(pattern) | |
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