-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.py
49 lines (37 loc) · 1003 Bytes
/
6.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
from AoCLibrary import *
with open("input6.txt") as f:
real_input = f.read()
def main(a : str):
a = a.strip()
inp = AdventInput(data=a)
ret = 1
times = nums(inp.lines[0])
dists = nums(inp.lines[1])
ways = []
for time, dist in zip(times, dists):
ways.append(get_ways_for_race(time, dist))
# print(ways)
times = int(string(times))
dists = int(string(dists))
return prod(ways), get_ways_for_race(times, dists)
def get_ways_for_race(time, dist):
winning_ways_for_race = 0
for i in range(time + 1):
cur = (time - i) * i
if cur > dist:
winning_ways_for_race += 1
return winning_ways_for_race
samp = r"""
Time: 7 15 30
Distance: 9 40 200
""".lstrip("\n")
if samp and "r" not in sys.argv:
sample_answer = main(samp)
print("sample", sample_answer)
else:
print("no sample provided")
if "s" in sys.argv:
exit()
result = main(real_input)
if result is not None:
ans(result)