-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay6WaitForIt.py
More file actions
27 lines (23 loc) · 852 Bytes
/
Day6WaitForIt.py
File metadata and controls
27 lines (23 loc) · 852 Bytes
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
import sys, os
import numpy as np
def parse_input(fname):
with open(fname) as file:
time_string = file.readline()
curr_record_string = file.readline()
times = [int(x.rstrip('\n')) for x in time_string.split(': ')[1].split(' ') if x.rstrip('\n').isnumeric()]
records = [int(x) for x in curr_record_string.split(': ')[1].split(' ') if x.isnumeric()]
return times, records
if __name__ == '__main__':
input_file = 'Day6Input.txt'
# input_file = 'Day6Input_test.txt'
times, records = parse_input(input_file)
print(times)
print(records)
def get_winning(time,record):
hold_time = np.arange(time)
distance = hold_time * (time-hold_time)
return sum(distance>record)
sol = 1
for time, record in zip(times, records):
sol *= get_winning(time,record)
print(sol)