diff options
Diffstat (limited to '2024/day6')
-rw-r--r-- | 2024/day6/input | 130 | ||||
-rw-r--r-- | 2024/day6/input_test | 10 | ||||
-rw-r--r-- | 2024/day6/solve.py | 55 |
3 files changed, 195 insertions, 0 deletions
diff --git a/2024/day6/input b/2024/day6/input new file mode 100644 index 0000000..f297efc --- /dev/null +++ b/2024/day6/input @@ -0,0 +1,130 @@ +........#.............................#......#................#..................#..................#.........#.#.#...............
+...........................................#..#......................#............................#...........................#.#.
+.............#..........#........#.#...........#........................#............................##...........................
+............#.............#.....................................#........................#.....#..................................
+.........#...........#................#................................#......#.....................#.............#..............#
+...........................##...........................................................................................#.........
+...........#.......#.................................................................#..............#....................#........
+.......................#.............................................#.........................................#.#..............#.
+.#...................#..................#...........#...#.........#...##..........................................................
+.................#..........#.....#.........#.....................................................................#..........##...
+....#.#............#..........#.......................#.........................#.................#.........#.............#....#..
+...#....................................#.............#..............................#............#.....................#........#
+....................#..............................#...#.#...#.#..........#.................................#..................#..
+........................................................................................#.....#.........#............#.........#..
+...................#.................#.......................................................................................#...#
+..............#.......#..................#........#....#........#.....................#..........................#................
+...........#..#....................................#.............#.#..#.......................................#.........#.#...#...
+...#.............#............................#..............#....................#.#.............................................
+..#...........#.#.........#...............................................#...#...............#.#...........#........##....#......
+.............................................#..#.........#......#................................................................
+.................................#.................#..............#.....#...................................................#.....
+............................#.......#............#...............................................................#................
+.....#....................#...........................................#..........................#..........#..#...#......#...#...
+........................#......#...#.......................#....##.......#..........#...............#.............................
+#..#....................................................................................................#.........................
+...........................................#......#..........................#..............................#.............#.....#.
+..............#......................#..#...................................#.#..................#.......#............#...........
+.................#...................................#..........#......#....#.#.#...#....................#..........#......#......
+........#....................................#........#.........................................#......#.#...............#......#.
+..................................#......#........#........#.#......#.........................#.#.......#......................#..
+......#..#.........#............#...........................................................#.............#.........#.............
+.........................#......................#.....#........#..........#.......................................................
+#.......#..................#............................................................#.........................................
+.........#.....#.............#...............#......#.....................#.......................................................
+.........#..#.........................................................#.........##..................##........#...................
+.#.....#..............#..............#.........................................#.....................................#............
+..............................#......................................................................................#............
+..............#..........................#................................#.#.....#...........#.........#.........................
+....................#...#.#...........................................................................#...........#...............
+...........#.............................#....................#........#...............................##....#....................
+.....................#......................#.#.....#...........................#.......#........#................................
+#..........#...............#.......#..................................#.....................................................##....
+.........................................................#...#....#...............................................#.........##....
+.....................#......................#..............#..................................................#...................
+......#.............#........#..................................................#...#.............................#......#........
+....................#............#........#...............#......#.......#........................................................
+..........................................................................#........................#......#.............#.......#.
+.....................................................#..#........#....................#.....................#.....................
+..#.................#........................................#................................................##...............#..
+.............#......#.........#................................................................................#..................
+#......#.......................................................................................................#......#...........
+.......##.......................#...................#.........##..........#.............................#........................#
+...........................................................#................................#...............#............##.......
+..........................#...................#...........................................................#.............#........#
+...#......................#..##................................................................................................#..
+............#..#.........#...#.........................................................#........#..............#..................
+.................#.................#........#............................................................................#........
+............#..#..#..#....#...........................#.................................................#..#...................#..
+....................................................#..#.................................#.#..............................#.......
+.........#.#................................................#..#............................................................#.....
+...##............................................#.....#.#...........................#....#.................#.#..........#........
+...............#.#.#.........................................#......#.....#..............................................#....#...
+.............#........................................#....#.......................................#...#....#.....................
+...........#.................................#...............................................#...........#..#..#......#...........
+#.......................................###....#....#.........................................#......#.............#..............
+...............#.#.....................................................................................#....................#.....
+##.........#..............#................................#..#..#..........#....................#..#..........#.....#............
+...................#..........................................#........................#.......................................#..
+#........#.#.....#............................................................##......#....#...........................#..........
+...............##....#.............#......................................#......................#...................#.#..........
+....................................##....#.............................................#..........#...................#....#.....
+.....#...............#........#..............#.............#..#..#...#.................................................#.#...##...
+........##.....................................................#..................................................................
+.........#.............................................................#..........................................................
+.............#.............#............................................................................#....#..........#.......#.
+.#........#...........................................#....#.........#......#............#.#................................#....#
+...............................................#.......#.............#.............#....................#.....................#...
+......................................#....................................................#...................................#..
+....#........#.....................................................#.......................................##.....................
+..........................................#............................................#.......#.....................#...#........
+................#.#.............#.....#....................#............#.............................................#...........
+..............................#..............#.................#...................#...#.......#..................................
+.#...............................................................#..................#......#............#................#........
+...................................#.................................##...........................................................
+...............................................................#....#..##...................#..#..............................#...
+..............................#...........#.................................................#.#....#...............#.....#........
+............................#........#.........#.........................................#....#...................................
+........................#................................................#....#..............#.........................#..........
+.........#....#....................#.......................#.#.......................................................#............
+.........................#......................................................#.................................................
+.............#...#...........#...................#.#..............^........................................#....#.................
+.................##...............................................................................................................
+..................#......#..............................#...............#.##.........................#............................
+....................................................###...........................................................................
+........#....................................................#........#........................................##...#.......#.....
+.........................##.....#.........................................................................#.........#.............
+.................#...........................................................................#........#..............#..#.........
+.........#.#..................................#..#...................................#.................................#..........
+.....#............#...#............#..............................#..........#.........#....#...........#.........................
+#...#...........................................................................................#.....#....#.........#.....#......
+......................................................#.#...............#......#.................#...............#.............#..
+.......................................................................................#.........#...#...........#..............#.
+.........................#................#.................#...............................#........#.##....................#....
+.....#...#................................#......................#...........#........................................#..#........
+.................#................................#.#.....................#............................................#....#.....
+...................#............................................................................#........#.....................##.
+.....#.................................................................#..................#........#.......#...#..................
+...............................#..#...................................#..........#...........#......................#.............
+....#................#..................#..........................................................................#........#.....
+......#.........................#............................................#....................#....#..........................
+.#.......#....#.#...#....#................#........................#...................#...................#......#...............
+..#...................#......#.#........#.........................#.........................#............#........................
+..#....#...#.......................................................................#......................#....................#..
+.......#...#............................................................#.................#......................................#
+..##..........#..................#...............#.....#..#...........#....#...............................................#......
+...##....#............##..................................................................................................#.......
+...........#.........................#....#......#...#.............................................#....................#........#
+............................................................................#...............#..#..............#...................
+.....#............................#.....................................................................................#......#.#
+.........#.............................#.....#.........................................................#.#.....#..................
+.......................#..#.#.......#..#................................#.....#..............#.........................#..........
+.................#.....................#............................................................................#........#....
+........#...............................................................#....#........#.........#.......#......#......#...........
+..............#............#......#..............#.#...........#.............................##...##.#..............#.....#.......
+##....................................................................#.......................#.................#.................
+............#...................................................................................................................#.
+...#....#....................#..............................................................................#........#............
+....#......................#......................................................#...............................................
+.#...#...........#....#........#...#.................#..............................#................#.##.........................
+...#.................#..............................#................................#...........#................................
\ No newline at end of file diff --git a/2024/day6/input_test b/2024/day6/input_test new file mode 100644 index 0000000..f76349a --- /dev/null +++ b/2024/day6/input_test @@ -0,0 +1,10 @@ +....#.....
+.........#
+..........
+..#.......
+.......#..
+..........
+.#..^.....
+........#.
+#.........
+......#...
\ No newline at end of file diff --git a/2024/day6/solve.py b/2024/day6/solve.py new file mode 100644 index 0000000..7e8a972 --- /dev/null +++ b/2024/day6/solve.py @@ -0,0 +1,55 @@ +import sys
+
+lines = []
+with open("input") as f:
+ for line in f.readlines():
+ lines.append(list(line.strip()))
+
+found_guard = False
+guard_row_idx = None
+guard_col_idx = None
+direction = None
+
+directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
+
+for line_idx, line in enumerate(lines):
+ for icon_idx, guard_icon in enumerate(("^", ">", "v", "<")):
+ if guard_icon in line:
+ guard_row_idx = line_idx
+ guard_col_idx = line.index(guard_icon)
+ direction = directions[icon_idx]
+ found_guard = True
+ break
+
+ if found_guard:
+ break
+
+if not found_guard:
+ sys.exit("Could not found guard.")
+
+row_count = len(lines)
+col_count = len(lines[0])
+while True:
+ lines[guard_row_idx][guard_col_idx] = "X"
+ new_row_idx = guard_row_idx + direction[0]
+ new_col_idx = guard_col_idx + direction[1]
+
+ if new_row_idx < 0 or new_row_idx >= row_count or new_col_idx < 0 or new_col_idx >= col_count:
+ break
+
+ if lines[new_row_idx][new_col_idx] == "#":
+ dir_idx = directions.index(direction)
+ if dir_idx == len(directions) - 1:
+ dir_idx = 0
+ else:
+ dir_idx += 1
+ direction = directions[dir_idx]
+ else:
+ guard_row_idx = new_row_idx
+ guard_col_idx = new_col_idx
+
+count = 0
+for line in lines:
+ count += line.count("X")
+
+print(count)
|