-
-
Save pawlos/a24ba3c943e5ef6bd79282c81a220547 to your computer and use it in GitHub Desktop.
Solution to Day 6: Memory Reallocation - part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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