From aa7ddad8c6949b5dfb7a4c77b49c5e65ae5aa782 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 7 Dec 2025 06:34:41 +0100 Subject: Day 7 2025 --- 2025/07/a.py | 17 +++++++++++++++-- 2025/07/b.py | 15 +++++++++++++++ 2025/README.md | 11 +++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 2025/07/b.py (limited to '2025') diff --git a/2025/07/a.py b/2025/07/a.py index 5fdb11b..0e13b75 100644 --- a/2025/07/a.py +++ b/2025/07/a.py @@ -1,6 +1,19 @@ import fileinput with fileinput.input() as lines: - for line in lines: - ... + rows = [line[:-1] for line in lines] + pos = [rows[0].find('S')] +s = 0 +for row in rows[1:]: + newpos = set() + for p in pos: + if row[p] == '^': + s += 1 + newpos.add(p-1) + newpos.add(p+1) + else: + newpos.add(p) + pos = list(newpos) + +print(s) diff --git a/2025/07/b.py b/2025/07/b.py new file mode 100644 index 0000000..41c0db0 --- /dev/null +++ b/2025/07/b.py @@ -0,0 +1,15 @@ +import fileinput + +with fileinput.input() as lines: + rows = [line[:-1] for line in lines] + pos = {rows[0].find('S'): 1} + +for row in rows[1:]: + newpos = {} + for p, w in pos.items(): + for pp in [p-1,p+1] if row[p] == '^' else [p]: + t = newpos.get(pp, 0) + newpos[pp] = t + w + pos = dict(newpos) + +print(sum(pos.values())) diff --git a/2025/README.md b/2025/README.md index 548deb3..c859ec8 100644 --- a/2025/README.md +++ b/2025/README.md @@ -11,6 +11,7 @@ Example ``` Day -Part 1- -Part 2- + 7 00:05:27 00:20:40 6 00:13:38 01:49:24 5 00:04:39 00:22:19 4 00:25:36 00:27:49 @@ -85,3 +86,13 @@ smart, very accomplishment. This year so far the only problems that took me more than 30 minutes are this and the first one, not exactly the hardest problems imaginable. + +### Day 7: Laboratories + +This was quite fun! For part 1, I iterate over the rows of the diagram +keeping a list of the position currently occupied by a tachyon. I use a +Python set to avoid duplicates. Part 2 is very similar, but the set is +changed to a map where the keys are the positions and the values are the +number of multiverses where a tachyon is in that position. To update +this value for the current row, I sum the values of all tachyons that +end there from the previous row (that can be one or two tachyons). -- cgit v1.3