-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday06.py
57 lines (39 loc) · 1.11 KB
/
day06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'''Advent of Code Day 6'''
# Part One
banks = [0, 2, 7, 0]
cycle = 0
prev_state = []
def string_value(int_list):
sv = ''.join(list(map(str, banks)))
return sv
def loop(start, distance, item):
if (start + distance) > end:
for i in range(start, end):
item[i] = item[i] + 1
print(item)
distance = distance - 1
else:
for i in range(start, start + distance):
print(start)
item[i] = item[i] + 1
print(item)
distance = distance - 1
return(0, distance, item)
prev_state = [string_value(banks), ]
current = None
while current not in prev_state:
prev_state.append(current)
end = len(banks)
highest = max(banks)
high_index = banks.index(highest)
banks[high_index] = 0
status = (high_index + 1, highest, banks)
while status[1]:
status = loop(status[0], status[1], status[2])
current = string_value(banks)
print(banks, 'end')
cycle = cycle + 1
prev_state.append(current)
# Part Two
'''Solution for part two is the same code,
but use the output of part 1 as input.'''