From cd72bdfd1466db5beec74e0c216049c66fbbf036 Mon Sep 17 00:00:00 2001 From: Samuel Ortion Date: Sat, 16 Dec 2023 09:16:45 +0100 Subject: [PATCH] day6: solve both parts --- days/06/part1.py | 28 ++++++++++++++++++++++++++++ days/06/part2.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 days/06/part1.py create mode 100644 days/06/part2.py diff --git a/days/06/part1.py b/days/06/part1.py new file mode 100644 index 0000000..19773a3 --- /dev/null +++ b/days/06/part1.py @@ -0,0 +1,28 @@ +with open("data/input.txt", "r") as f: + data = f.read() + +data = data.split("\n") +times = data[0].split(":")[1].split() +distances = data[1].split(":")[1].split() + +times = [int(i) for i in times] +distances = [int(i) for i in distances] + +# print(times) +# print(distances) + +product = 1 + + +def distance(pressed_duration, limit_duration): + return pressed_duration * (limit_duration - pressed_duration) + + +for time, dist in zip(times, distances): + count = 0 + for i in range(0, time + 1): + if distance(i, time) > dist: + count += 1 + product *= count + +print(product) diff --git a/days/06/part2.py b/days/06/part2.py new file mode 100644 index 0000000..43cbf77 --- /dev/null +++ b/days/06/part2.py @@ -0,0 +1,28 @@ +with open("data/sample.txt", "r") as f: + data = f.read() + +data = data.split("\n") +times = data[0].split(":")[1].replace(" ", "").split() +distances = data[1].split(":")[1].replace(" ", "").split() + +times = [int(i) for i in times] +distances = [int(i) for i in distances] + +# print(times) +# print(distances) + +product = 1 + + +def distance(pressed_duration, limit_duration): + return pressed_duration * (limit_duration - pressed_duration) + + +for time, dist in zip(times, distances): + count = 0 + for i in range(0, time + 1): + if distance(i, time) > dist: + count += 1 + product *= count + +print(product)