62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
#!/bin/python3
|
|
import sys
|
|
from pprint import pprint
|
|
|
|
input_f = sys.argv[1]
|
|
|
|
#########################################
|
|
# #
|
|
# Part 1 #
|
|
# #
|
|
#########################################
|
|
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-found_at)
|
|
print(steps)
|
|
#########################################
|
|
# #
|
|
# Part 2 #
|
|
# #
|
|
#########################################
|