From 8cfa72a7e93644c308f80f4eaa21763019ea0360 Mon Sep 17 00:00:00 2001 From: Simon Junod Date: Mon, 1 Dec 2025 08:19:52 +0100 Subject: [PATCH] Days 1 and 2 --- .gitignore | 1 + 1/a.py | 13 +++++++++++++ 1/b.py | 16 ++++++++++++++++ 2/a.py | 16 ++++++++++++++++ 2/b.py | 16 ++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 .gitignore create mode 100644 1/a.py create mode 100644 1/b.py create mode 100644 2/a.py create mode 100644 2/b.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3f9177e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +input diff --git a/1/a.py b/1/a.py new file mode 100644 index 0000000..731fb87 --- /dev/null +++ b/1/a.py @@ -0,0 +1,13 @@ +with open("input", "r") as f: + lines = f.read().splitlines() + +p = 50 + +for line in lines: + d = line[0] + n = int(line[1:]) + if d == "L": + n *= -1 + p += n + p %= 100 + print(p) diff --git a/1/b.py b/1/b.py new file mode 100644 index 0000000..7810c9b --- /dev/null +++ b/1/b.py @@ -0,0 +1,16 @@ +with open("input", "r") as f: + lines = f.read().splitlines() + +p = 50 + +for line in lines: + d = line[0] + n = int(line[1:]) + + for i in range(n): + if d == "R": + p += 1 + else: + p -= 1 + p %= 100 + print(p) diff --git a/2/a.py b/2/a.py new file mode 100644 index 0000000..da2e93e --- /dev/null +++ b/2/a.py @@ -0,0 +1,16 @@ +import re + +with open("input", "r") as f: + line = f.read() + +ranges = line.split(",") + +s = 0 + +for _range in ranges: + start, end = list(map(int, _range.split("-"))) + for i in range(start, end+1): + if re.match(r"^(.+)\1$", str(i)): + s += i + +print(s) diff --git a/2/b.py b/2/b.py new file mode 100644 index 0000000..df05556 --- /dev/null +++ b/2/b.py @@ -0,0 +1,16 @@ +import re + +with open("input", "r") as f: + line = f.read() + +ranges = line.split(",") + +s = 0 + +for _range in ranges: + start, end = list(map(int, _range.split("-"))) + for i in range(start, end+1): + if re.match(r"^(.+)\1+$", str(i)): + s += i + +print(s)