-
-
Save kbkk/301654273a1dcf2fa7f91b05c2b6f9fe to your computer and use it in GitHub Desktop.
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
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