-
Notifications
You must be signed in to change notification settings - Fork 0
/
day13.py
40 lines (32 loc) · 1.04 KB
/
day13.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
import math
inp_f = open("input/day13.txt", "r")
inp = inp_f.read()
inp_list = [line for line in inp.split("\n") if line != ""]
def part1():
earliest_time = int(inp_list[0])
ids = [int(num) for num in inp_list[1].split(",") if num != "x"]
best_id = None
best_time = None
for num in ids:
dividend = math.ceil(earliest_time / num)
this_time = num * dividend
if best_time is None or best_time > this_time:
best_time = this_time
best_id = num
return (best_time - earliest_time) * best_id
def part2():
ids = [int(num) for num in inp_list[1].split(",") if num != "x"]
idxs = [i for i, num in enumerate(inp_list[1].split(",")) if num != "x"]
inc_idx = 0
inc = ids[inc_idx]
comp = 0
while True:
if (comp + idxs[inc_idx+1]) % ids[inc_idx+1] == 0:
inc_idx += 1
inc *= ids[inc_idx]
if inc_idx == len(ids)-1:
return comp
comp += inc
if __name__ == "__main__":
# print(part1())
print(part2())