AdventOfCode/2017/06/solution.py

57 lines
1.3 KiB
Python
Raw Permalink Normal View History

2024-11-15 19:41:45 +01:00
#!/bin/python3
import sys
from pprint import pprint
input_f = sys.argv[1]
#########################################
# #
2024-11-16 08:05:16 +01:00
# Part 1+2 #
2024-11-15 19:41:45 +01:00
# #
#########################################
line = []
tests = []
with open(input_f) as file:
for line in file:
line = line.rstrip().split()
line = list(map(int, line))
tests = []
steps = 0
tests.append(''.join(map(str,line)))
stop = False
while stop != True: #line not in tests:
steps+=1
idmx,mx = max(enumerate(line),key=lambda x: x[1])
tmp = idmx
#print(line)
#print(tests)
#print('Max [',idmx,'] =',mx)
while True:
#print(line)
#print('Min:',min(line))
#print(line[idmx])
#print('mx:',mx)
idmx = (idmx + 1) % len(line)
line[idmx] += 1
line[tmp] -= 1
#print(mx,min(line))
if mx == 1:
#print('APPENDING')
if ''.join(map(str,line)) in tests:
found_at = tests.index(''.join(map(str,line)))
#print(''.join(map(str,line)),tests)
stop = True
tests.append(''.join(map(str,line)))
break
mx -= 1
#input()
#input()
#print(tests)
#print(line)
print(steps)
2024-11-16 08:05:16 +01:00
print(steps-found_at)