Skip to content

Commit

Permalink
[2024/4] refactor to use Grid.find_all() - it does the row/col enumer…
Browse files Browse the repository at this point in the history
…ation and position building already
  • Loading branch information
StarlitGhost committed Dec 4, 2024
1 parent b955202 commit e1f4036
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
Binary file modified .aoc_tiles/tiles/2024/04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 6 additions & 17 deletions 2024/4/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,16 @@ def main():
grid = Grid(aoc.read_lines())

xmas_count = 0
for y, row in enumerate(grid):
for x, cell in enumerate(row):
if cell == 'X':
xmas_count += search_xmas(grid, Vec2(x, y))
else:
continue
for pos in grid.find_all('X'):
xmas_count += search_xmas(grid, Vec2(pos))
print("p1:", xmas_count)

masx_count = 0
for y, row in enumerate(grid):
# skip the top and bottom rows
if y in [0, grid.height() - 1]:
for pos in grid.find_all('A'):
# skip As at the edge of the grid
if pos[0] in [0, grid.width() - 1] or pos[1] in [0, grid.height() - 1]:
continue
for x, cell in enumerate(row):
# skip the left and right columns
if x in [0, grid.width() - 1]:
continue
if cell == 'A':
masx_count += search_masx(grid, Vec2(x, y))
else:
continue
masx_count += search_masx(grid, Vec2(pos))
print("p2:", masx_count)


Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ My solutions to the yearly Advents of Code

<!-- AOC TILES BEGIN -->
<h1 align="center">
Advent of Code - 168/458 ⭐
Advent of Code - 169/458 ⭐
</h1>
<h1 align="center">
2024 - 7 ⭐ - Python
2024 - 8 ⭐ - Python
</h1>
<a href="2024/1/script.py">
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
Expand Down

0 comments on commit e1f4036

Please sign in to comment.