From 200a9c18a970ee67981651ada5526a5aeaa1b108 Mon Sep 17 00:00:00 2001 From: Starnakin Date: Thu, 5 Dec 2024 14:24:55 +0100 Subject: [PATCH] add: 2024/day02/part1 --- 2024/day02/part1.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 2024/day02/part1.py diff --git a/2024/day02/part1.py b/2024/day02/part1.py new file mode 100644 index 0000000..e568180 --- /dev/null +++ b/2024/day02/part1.py @@ -0,0 +1,21 @@ +text: str + +with open("input.txt") as f: + text = f.read() + +lines: list[str] = text.splitlines() + +total: int = 0 + +for line in lines: + numbers: list[int] = list(map(int, line.split(" "))) + direction: int = (numbers[1] - numbers[0]) + if (direction == 0): + continue + direction = direction / abs(direction) + for x1, x2 in zip(numbers[:-1], numbers[1:]): + if ((x2 - x1) * direction not in range(1, 4)): + break + else: + total += 1 +print(total) \ No newline at end of file