Skip to content

Instantly share code, notes, and snippets.

@kbkk
Last active December 6, 2017 16:57
Show Gist options
  • Save kbkk/301654273a1dcf2fa7f91b05c2b6f9fe to your computer and use it in GitHub Desktop.
Save kbkk/301654273a1dcf2fa7f91b05c2b6f9fe to your computer and use it in GitHub Desktop.
banks = [int(x) for x in open('data.txt', 'r').read().split("\t")]
memory_history = {}
counter = 0
since_last_occurence = 0
def redistribute():
bank = banks.index(max(banks))
bank_size = banks[bank]
banks[bank] = 0
for i in range(0, bank_size):
banks[(i + 1 + bank) % banks.__len__()] += 1
while True:
counter += 1
redistribute()
hash = ''.join(chr(i) for i in banks)
if hash in memory_history:
since_last_occurence = counter - memory_history[hash]
break
memory_history[hash] = counter
print("First part: " + str(counter))
print("Second part: " + str(since_last_occurence))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment