My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2023/06

+29
+29
2023/day06.py
··· 1 + import fileinput 2 + from utils import mul 3 + 4 + 5 + def solve(time, record): 6 + num_wins = 0 7 + for hold_time in range(time + 1): 8 + total_distance = hold_time * (time - hold_time) 9 + if total_distance > record: 10 + num_wins += 1 11 + 12 + return num_wins 13 + 14 + 15 + # Parse problem input. 16 + for i, line in enumerate(fileinput.input()): 17 + if i == 0: 18 + times = [int(x) for x in line.split()[1:]] 19 + else: 20 + distances = [int(x) for x in line.split()[1:]] 21 + 22 + 23 + # Solve problem. 24 + print("Part 1:", mul(solve(time, record) for time, record in zip(times, distances))) 25 + 26 + part_2_time = int(''.join(str(n) for n in times)) 27 + part_2_distance = int(''.join(str(n) for n in distances)) 28 + print("Part 2:", solve(part_2_time, part_2_distance)) 29 +