diff --git a/.aoc_tiles/tiles/2024/06.png b/.aoc_tiles/tiles/2024/06.png new file mode 100644 index 0000000..7780984 Binary files /dev/null and b/.aoc_tiles/tiles/2024/06.png differ diff --git a/2024/6/example b/2024/6/example new file mode 100644 index 0000000..a4eb402 --- /dev/null +++ b/2024/6/example @@ -0,0 +1,10 @@ +....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#..^..... +........#. +#......... +......#... diff --git a/2024/6/script.py b/2024/6/script.py new file mode 100644 index 0000000..ef75794 --- /dev/null +++ b/2024/6/script.py @@ -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() diff --git a/README.md b/README.md index b43cff1..5a86a3d 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ My solutions to the yearly Advents of Code