Skip to content

Instantly share code, notes, and snippets.

@pawlos
Last active December 24, 2017 18:47
Show Gist options
  • Save pawlos/a24ba3c943e5ef6bd79282c81a220547 to your computer and use it in GitHub Desktop.
Save pawlos/a24ba3c943e5ef6bd79282c81a220547 to your computer and use it in GitHub Desktop.
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