-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2.py
47 lines (33 loc) · 1.02 KB
/
part2.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
from pathlib import Path
banks = [int(c) for c in Path(Path(__file__).parent, "input").read_text().split("\t")]
visited_configs: set[str] = {"".join(map(str, banks))}
cycle = 0
while True:
cycle += 1
max_bank = max(banks)
idx_max_bank = banks.index(max_bank)
banks[idx_max_bank] = 0
i_bank = (idx_max_bank + 1) % len(banks)
for _ in range(max_bank):
banks[i_bank] += 1
i_bank = (i_bank + 1) % len(banks)
config = "".join(map(str, banks))
if config in visited_configs:
break
visited_configs.add(config)
visited_configs = {"".join(map(str, banks))}
cycle = 0
while True:
cycle += 1
max_bank = max(banks)
idx_max_bank = banks.index(max_bank)
banks[idx_max_bank] = 0
i_bank = (idx_max_bank + 1) % len(banks)
for _ in range(max_bank):
banks[i_bank] += 1
i_bank = (i_bank + 1) % len(banks)
config = "".join(map(str, banks))
if config in visited_configs:
break
visited_configs.add(config)
print(f"Result: {cycle}")