generated from public/aoc_template
53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(288, "input6_test"),
|
|
(219849, "input6"),
|
|
],
|
|
[
|
|
(71503, "input6_test"),
|
|
(29432455, "input6"),
|
|
],
|
|
]
|
|
|
|
def part1(self) -> Any:
|
|
race_times, race_dists = self.getIntsFromInput()
|
|
ans = 1
|
|
|
|
for i, duration in enumerate(race_times):
|
|
count = 0
|
|
for ms in range(duration):
|
|
t = race_dists[i]
|
|
if ms * (duration - ms) > t:
|
|
count += 1
|
|
|
|
ans *= count
|
|
return ans
|
|
|
|
def part2(self) -> Any:
|
|
race_times, race_dists = self.getIntsFromInput()
|
|
time = int("".join(map(str, race_times)))
|
|
dist = int("".join(map(str, race_dists)))
|
|
|
|
lower, higher = 0, 0
|
|
for ms in range(time):
|
|
if ms * (time - ms) > dist:
|
|
lower = ms
|
|
break
|
|
|
|
for ms in range(time, 0, -1):
|
|
if ms * (time - ms) > dist:
|
|
higher = ms
|
|
break
|
|
|
|
return higher - lower + 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
day = Day(2023, 6)
|
|
day.run(verbose=True)
|