Skip to content

Commit

Permalink
2024 day 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeni Gordeev committed Jan 8, 2025
1 parent 228b71d commit baaf8e9
Show file tree
Hide file tree
Showing 5 changed files with 1,499 additions and 5 deletions.
1 change: 1 addition & 0 deletions 2024.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ hyperfine --warmup 3 -r 10 'find 2024 -type f -regex ".*/[0-9]*\.py" | sort -n |
| [02](https://adventofcode.com/2024/day/2) | Red-Nosed Reports | [py](2024/02.py) | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/EvgeniGordeev/13c6cac3c39702cdcb9cc169b66c3210/raw/runtime-badge-2024-02-ci.json)](https://github.com/EvgeniGordeev/adventofcode/actions/workflows/ci2024.yaml) |
| [03](https://adventofcode.com/2024/day/3) | Mull It Over | [py](2024/03.py) | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/EvgeniGordeev/13c6cac3c39702cdcb9cc169b66c3210/raw/runtime-badge-2024-03-ci.json)](https://github.com/EvgeniGordeev/adventofcode/actions/workflows/ci2024.yaml) |
| [04](https://adventofcode.com/2024/day/4) | Ceres Search | [py](2024/04.py) | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/EvgeniGordeev/13c6cac3c39702cdcb9cc169b66c3210/raw/runtime-badge-2024-04-ci.json)](https://github.com/EvgeniGordeev/adventofcode/actions/workflows/ci2024.yaml) |
| [04](https://adventofcode.com/2024/day/5) | Print Queue | [py](2024/05.py) | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/EvgeniGordeev/13c6cac3c39702cdcb9cc169b66c3210/raw/runtime-badge-2024-05-ci.json)](https://github.com/EvgeniGordeev/adventofcode/actions/workflows/ci2024.yaml) |
| ----------------------------------------- | --------------------------------- | ------------------------- | --- |
| [all](https://adventofcode.com/2024) | AoC 24 | [txt](2024/answers.txt) | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/EvgeniGordeev/13c6cac3c39702cdcb9cc169b66c3210/raw/runtime-badge-2024-all-ci.json)](https://github.com/EvgeniGordeev/adventofcode/actions/workflows/ci2024.yaml) |

Expand Down
6 changes: 3 additions & 3 deletions 2024/04.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def neighbors(x, y) -> List[Tuple[int, int]]:
return [(x + i, y + j) for i in (-1, 0, 1) for j in (-1, 0, 1)
if (i, j) != (0, 0) and -1 < x + i < height and -1 < y + j < width]

def bfs(paths: List[List[Tuple[int, int]]]):
def dfs(paths: List[List[Tuple[int, int]]]):
# identified = []
counter = 0
for p in paths:
Expand All @@ -36,7 +36,7 @@ def bfs(paths: List[List[Tuple[int, int]]]):
for nx, ny in neighbors(x, y):
if len(p) < 2 or p[-2][0] - x == x - nx and p[-2][1] - y == y - ny: # word must not break, i.e. have the same direction
# identified.extend(bfs([p + [(nx, ny)]]))
counter += bfs([p + [(nx, ny)]])
counter += dfs([p + [(nx, ny)]])

# return identified
return counter
Expand All @@ -46,7 +46,7 @@ def bfs(paths: List[List[Tuple[int, int]]]):
for x in range(height):
for y in range(width):
# found.extend(bfs([[(x, y)]]))
result += bfs([[(x, y)]])
result += dfs([[(x, y)]])
# return len(found)
return result

Expand Down
Loading

0 comments on commit baaf8e9

Please sign in to comment.