1
0
Fork 0
adventofcode/2023/06/main.py
2024-12-30 19:45:55 +01:00

46 lines
1.2 KiB
Python

#!/usr/bin/env python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# Author: Sebastian Mark
# CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de)
# pylint: disable=missing-module-docstring,missing-function-docstring,consider-using-f-string
def readinput():
with open("input", "r", encoding="utf-8") as file:
times = file.readline().split()[1:]
distances = file.readline().split()[1:]
races = [(int(time), int(distance)) for time, distance in zip(times, distances)]
return races
def sprints(time: int, distance: int) -> list:
successfull = []
for presstime in range(time):
if (time - presstime) * presstime > distance:
successfull.append(presstime)
return successfull
def main():
races = readinput()
# part 1
count = 1
for time, distance in races:
count *= len(sprints(time, distance))
print("Number to record: %d" % count)
# part 3
time = int("".join(str(t) for t, _ in races))
distance = int("".join(str(d) for _, d in races))
count = len(sprints(time, distance))
print("Number to record: %d" % count)
if __name__ == "__main__":
main()