Skip to content

Commit

Permalink
[2024/6] p1 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlitGhost committed Dec 6, 2024
1 parent e6809db commit 28cba48
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
Binary file added .aoc_tiles/tiles/2024/06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions 2024/6/example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
....#.....
.........#
..........
..#.......
.......#..
..........
.#..^.....
........#.
#.........
......#...
30 changes: 30 additions & 0 deletions 2024/6/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from GhostyUtils import aoc
from GhostyUtils.grid import Grid
from GhostyUtils.vec2 import Vec2, Dir


def move(pos: Vec2, dir_: Dir, grid: Grid) -> tuple[Vec2, Dir]:
if not grid.in_bounds(pos + Vec2(dir_)) or not grid[pos + Vec2(dir_)] == '#':
return pos + Vec2(dir_), dir_
else:
return pos, dir_.turn_right()


def main():
grid = Grid(aoc.read_lines())
print(grid)

pos = grid.find('^')
dir_ = Dir.UP

visited = set()
visited.add(pos)
while grid.in_bounds(pos):
pos, dir_ = move(pos, dir_, grid)
visited.add(pos.as_tuple())

print("p1:", len(visited) - 1)


if __name__ == "__main__":
main()
7 changes: 5 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 - 171/460
Advent of Code - 172/462
</h1>
<h1 align="center">
2024 - 10 ⭐ - Python
2024 - 11 ⭐ - Python
</h1>
<a href="2024/1/script.py">
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
Expand All @@ -23,6 +23,9 @@ My solutions to the yearly Advents of Code
<a href="2024/5/script.py">
<img src=".aoc_tiles/tiles/2024/05.png" width="161px">
</a>
<a href="2024/6/script.py">
<img src=".aoc_tiles/tiles/2024/06.png" width="161px">
</a>
<h1 align="center">
2023 - 47 ⭐ - Python
</h1>
Expand Down

0 comments on commit 28cba48

Please sign in to comment.