diff --git a/2023/06/main.py b/2023/06/main.py new file mode 100644 index 0000000..27c74ad --- /dev/null +++ b/2023/06/main.py @@ -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()