This commit is contained in:
Stefan Harmuth 2023-12-06 06:16:03 +01:00
parent 16b657786a
commit 3a9d84cf92
3 changed files with 56 additions and 0 deletions

52
day06.py Normal file
View File

@ -0,0 +1,52 @@
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)

2
inputs/input6 Normal file
View File

@ -0,0 +1,2 @@
Time: 44 70 70 80
Distance: 283 1134 1134 1491

2
inputs/input6_test Normal file
View File

@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200