add 2023/day6
This commit is contained in:
parent
2b7037676d
commit
9d0149588c
1 changed files with 46 additions and 0 deletions
46
2023/06/main.py
Normal file
46
2023/06/main.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#!/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()
|
Loading…
Reference in a new issue