From 3c900f39ee72626ce57626c93f82ce1272daa315 Mon Sep 17 00:00:00 2001 From: kleph Date: Thu, 7 Dec 2023 02:37:52 +0100 Subject: [PATCH] 2023 - Day 6 part 1 --- 2023/6/6.py | 27 +++++++++++++++++++++++++++ 2023/6/input.txt | 2 ++ 2023/6/input_example.txt | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 2023/6/6.py create mode 100644 2023/6/input.txt create mode 100644 2023/6/input_example.txt diff --git a/2023/6/6.py b/2023/6/6.py new file mode 100644 index 0000000..259e70f --- /dev/null +++ b/2023/6/6.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# 2023 - Advent Of Code 6 + +import re + +# file = 'input_example.txt' +file = 'input.txt' + +races = [] + +with open(file, encoding="utf-8") as f: + times = re.findall(r"\s+(\d+)+\s?", f.readline()) + distances = re.findall(r"\s+(\d+)+\s?", f.readline()) + races = list(zip([int(x) for x in times], [int(x) for x in distances])) + print(races) + +res = 1 +for race in races: + count = 0 + for tpress in range(1, race[0]): + nb = tpress * (race[0] - tpress) + if nb > race[1]: + count += 1 + # print(f'{tpress}: {nb}') + print(count) + res *= count +print(res) diff --git a/2023/6/input.txt b/2023/6/input.txt new file mode 100644 index 0000000..e0996e8 --- /dev/null +++ b/2023/6/input.txt @@ -0,0 +1,2 @@ +Time: 60 80 86 76 +Distance: 601 1163 1559 1300 diff --git a/2023/6/input_example.txt b/2023/6/input_example.txt new file mode 100644 index 0000000..28f5ae9 --- /dev/null +++ b/2023/6/input_example.txt @@ -0,0 +1,2 @@ +Time: 7 15 30 +Distance: 9 40 200