diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-07 09:14:27 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-07 09:14:27 +0100 |
| commit | eb233235c876600bafa39a538d18ce11cfc72b39 (patch) | |
| tree | 38f074d2e158d8109476d39ea6426ce8b60e98b2 /2025 | |
| parent | 61718ca8b469ebad7ed59da0ed3c167046cd8e57 (diff) | |
| download | aoc-eb233235c876600bafa39a538d18ce11cfc72b39.tar.gz aoc-eb233235c876600bafa39a538d18ce11cfc72b39.zip | |
Clean up and alternative solution to day 7
Diffstat (limited to '2025')
| -rw-r--r-- | 2025/07/a.py | 2 | ||||
| -rw-r--r-- | 2025/07/b.py | 2 | ||||
| -rw-r--r-- | 2025/07/b2.py | 17 | ||||
| -rw-r--r-- | 2025/README.md | 4 |
4 files changed, 23 insertions, 2 deletions
diff --git a/2025/07/a.py b/2025/07/a.py index 0e13b75..53ff68c 100644 --- a/2025/07/a.py +++ b/2025/07/a.py | |||
| @@ -2,9 +2,9 @@ import fileinput | |||
| 2 | 2 | ||
| 3 | with fileinput.input() as lines: | 3 | with fileinput.input() as lines: |
| 4 | rows = [line[:-1] for line in lines] | 4 | rows = [line[:-1] for line in lines] |
| 5 | pos = [rows[0].find('S')] | ||
| 6 | 5 | ||
| 7 | s = 0 | 6 | s = 0 |
| 7 | pos = [rows[0].find('S')] | ||
| 8 | for row in rows[1:]: | 8 | for row in rows[1:]: |
| 9 | newpos = set() | 9 | newpos = set() |
| 10 | for p in pos: | 10 | for p in pos: |
diff --git a/2025/07/b.py b/2025/07/b.py index 41c0db0..4457654 100644 --- a/2025/07/b.py +++ b/2025/07/b.py | |||
| @@ -2,8 +2,8 @@ import fileinput | |||
| 2 | 2 | ||
| 3 | with fileinput.input() as lines: | 3 | with fileinput.input() as lines: |
| 4 | rows = [line[:-1] for line in lines] | 4 | rows = [line[:-1] for line in lines] |
| 5 | pos = {rows[0].find('S'): 1} | ||
| 6 | 5 | ||
| 6 | pos = {rows[0].find('S'): 1} | ||
| 7 | for row in rows[1:]: | 7 | for row in rows[1:]: |
| 8 | newpos = {} | 8 | newpos = {} |
| 9 | for p, w in pos.items(): | 9 | for p, w in pos.items(): |
diff --git a/2025/07/b2.py b/2025/07/b2.py new file mode 100644 index 0000000..b77188c --- /dev/null +++ b/2025/07/b2.py | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | import fileinput | ||
| 2 | |||
| 3 | with fileinput.input() as lines: | ||
| 4 | rows = [line[:-1] for line in lines] | ||
| 5 | |||
| 6 | t = [1 if x == 'S' else 0 for x in rows[0]] | ||
| 7 | for row in rows[1:]: | ||
| 8 | next = [0] * len(row) | ||
| 9 | for i in range(len(row)): | ||
| 10 | if row[i] == '^': | ||
| 11 | next[i-1] += t[i] | ||
| 12 | next[i+1] += t[i] | ||
| 13 | else: | ||
| 14 | next[i] += t[i] | ||
| 15 | t = next | ||
| 16 | |||
| 17 | print(sum(t)) | ||
diff --git a/2025/README.md b/2025/README.md index c859ec8..4ca1d2e 100644 --- a/2025/README.md +++ b/2025/README.md | |||
| @@ -96,3 +96,7 @@ changed to a map where the keys are the positions and the values are the | |||
| 96 | number of multiverses where a tachyon is in that position. To update | 96 | number of multiverses where a tachyon is in that position. To update |
| 97 | this value for the current row, I sum the values of all tachyons that | 97 | this value for the current row, I sum the values of all tachyons that |
| 98 | end there from the previous row (that can be one or two tachyons). | 98 | end there from the previous row (that can be one or two tachyons). |
| 99 | |||
| 100 | I added a second solution for part 2 that does not use a map, but only | ||
| 101 | lists. This could be seen as a dynamic programming problem where the | ||
| 102 | iterative implementation is more intuitive than the recursive one. | ||
