summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-12-06 00:02:27 -0700
committerJack Sangdahl <[email protected]>2024-12-06 00:02:27 -0700
commit55c619d52b19e90a3d233b96e5df8345e616d229 (patch)
treea060eeae6287011267a50bbc53c75f52ad3bf4cb
parenta3c129a57340bda27240cef0b5d6228d425e9314 (diff)
downloadaoc-55c619d52b19e90a3d233b96e5df8345e616d229.tar.gz
aoc-55c619d52b19e90a3d233b96e5df8345e616d229.zip
Day 6 2024
-rw-r--r--6_2024.py37
-rw-r--r--data/6_2024.txt130
2 files changed, 167 insertions, 0 deletions
diff --git a/6_2024.py b/6_2024.py
new file mode 100644
index 0000000..114cbc6
--- /dev/null
+++ b/6_2024.py
@@ -0,0 +1,37 @@
+infile = "data/6_2024.txt"
+data = open(infile).read().strip()
+lines = data.split("\n")
+p1, p2 = 0, 0
+rows = len(lines)
+cols = len(lines[0])
+
+
+for r in range(rows):
+ for c in range(cols):
+ if lines[r][c] == "^":
+ sr, sc = r, c
+for o_r in range(rows):
+ for o_c in range(cols):
+ r, c, d = sr, sc, 0
+ vis, vis_rc = set(), set()
+ while True:
+ if (r, c, d) in vis:
+ p2 += 1
+ break
+ vis.add((r, c, d))
+ vis_rc.add((r, c))
+ dr, dc = [(-1, 0), (0, 1), (1, 0), (0, -1)][d]
+ rr = r + dr
+ cc = c + dc
+ if not (0 <= rr < rows and 0 <= cc < cols):
+ if lines[o_r][o_c] == "#":
+ p1 = len(vis_rc)
+ break
+ if lines[rr][cc] == "#" or rr == o_r and cc == o_c:
+ d = (d + 1) % 4
+ else:
+ r = rr
+ c = cc
+
+print(p1)
+print(p2)
diff --git a/data/6_2024.txt b/data/6_2024.txt
new file mode 100644
index 0000000..1436e70
--- /dev/null
+++ b/data/6_2024.txt
@@ -0,0 +1,130 @@
+..................#................................................................#........#.....................................
+...#...........#...................................................#........................................#.................#...
+...................................#................#.#...............#.................................................#.........
+.....#......#................#.....................................................................#..........#........#......#...
+............................................................................................#.....................#...............
+.....................#..##...#........................#.................#.......................#..#.........#.......#...#......#.
+............##....................................##..................#...............................#....#......................
+.............#............#.#..#.......#...........#..............#...............#.....#.........................................
+....................#..........##.........#.........#................#............................................................
+....#.......#................................................................#...#.#..........................................#.#.
+..#..............#.....................................#..........#.#....#..............#..................#.#............#.......
+.#.......#.........................#........................#..#.....#............................................................
+........#...#......................#...........#......................................#....................#......................
+.............................#..............#........##....#....................#......#....................#............#......#.
+..............#..............#............#.......................##....#..........................................#.........#....
+.............#............#..........#..........#...#.....................................................#.......................
+..#........#.....#..........................................#................................................#...#.#...#..........
+........#.....................#...#..#......#.........................................................#.....##.........#..........
+..............................................................................................#...#...............................
+..#.......................#..........................#......#...................................................................#.
+.......#.........................#..............#.........#.............#.......................................#...#.............
+..................#.................#.......................#....................#....................................#...........
+...#...#.......#......##.#...............#....#..............#..........................................#....#..#.................
+#................................#.......#.....#.......#.............#..................#........#................................
+...........#..................................#.......................................................................#.#..#......
+.......#........#.........................................#..........................#...........................#.....#..........
+................#..#.....................#..#...........................#...........................................#.............
+#...#.......................#................................................#................#................................#..
+..........#...........................#.......#............................................................................#.....#
+..................................#............................................................#..................................
+......................#........#.............#....#.....#.......#..........................#..........................#...........
+...........................##.................#.............#........................#...#..................#.....................
+.............................................................................................................#....#..........#....
+................#...................................#...........#..........#....................#............................#....
+........#....#................................................#................##..#..................................#...........
+...........#....................................................#...#.#......#....................................................
+.......................#.........................................................^....................................#...........
+..........................#.............##..#........#.#....#.......#....................#...........#.........#.....#............
+........#...........................#..#..........................................................#...............................
+....#....................................#....#.........................................#.........#...............................
+...............#...................................#.....#.................................#....................................#.
+......#...............................................................#.............................#........................#....
+.........................#.....#.........................#.#...............#.........#.....#..................#..#.........#......
+.........................................................#......#........##.......................#...#......#................#...
+.......................................#.....#.................................#..................................................
+..................#..................................#..........................................................................#.
+...................#....#.........#.......#................#....................#.........................#......#.....#..#.......
+................................#..............................................................................#....#.............
+.....................#.#.............#.................#..........#.......#.........................................#.............
+......#....................#....................................................................#...#.............................
+........#........#...........#.##.............#........................#............#..............#.........#....#........#......
+........................#.................................................................#.......................................
+............................................................#.....#....................#............#.....#....#............#.....
+...........#............#....#........................................................##............#..............#..............
+...........#...........#.....#..............#..............##....#........#......#................................................
+..#................................................................................#......................#......#................
+....................#.........#......................#.............................#.......#.......................#.............#
+..#...#....#......................................................................................................#...............
+...........#................................................................................#...............................#.....
+....................................#............#..........#.........................#..................................#.......#
+...................#......#...................#............#......#........#................#.............#...........#.........#.
+........................#..................................#........#..................#..........................................
+............#..#...........#..................##....................#...........................................#.................
+.......................................................................................#.....#............#.......................
+...............................................#....#................................#..#..........................#..#...........
+..............#..#.....#.........#....................#.......#..#..............#...............................#.....#...........
+..........#............................#..........................................................................................
+........................................#........#........................................................#.#.....................
+#................#......................#..................................................................................#......
+...............................................................................#................................#.................
+...................................................................................................................#.#........#...
+#........................................................................#......................................#.#...............
+...#......#............#...................#.............#........#..........................................#......#.............
+..............##....#...................................................#......................#..................................
+...............#........................................................................#...........#...#.#.......................
+..........#.#.....#................................#...........#........#.......#.................................................
+#....................#......................................................................................#.....................
+..............#...##...........................................#.............#.......#..................#..............#..........
+.#.............................................#..............................................................................#...
+...#................................#............................................#............................#...................
+..............................#......................................................#..........................................#.
+...................#.....................................#..................................#......#..............................
+....#.#..........##.............#.......#........................##..........#.................#..................................
+#..#................#........##....................................................................................#..............
+........#...#.........................................................................#...........................................
+......................................................#....#...................#..#.................................#.............
+........#...............#........#..............................................#............................#....................
+...#..............................#.........................................##.......................................#....#.......
+...#................#..............#.......#......................................................................................
+........#..................#.............................................................#...........................#....#.......
+......................#.#..........#.......#..................................#..#...#............#...............#...............
+.....#..................#....#..#......#.......................#.....................................................#............
+.....#................................#.........................#..................#.#..........#...#............#.....#..........
+....#...................#....#.#.........#........#..................................................................#....#..#....
+........#...............#......................................#........#..............................#..........................
+....#...#.#.....#..............#..................#..........#...#..#......................#...#..........#......................#
+...........#...................................................................................................#................#.
+.................................##..............#.............................#...............................#..................
+...........#.................#.............##...................................#.......................#.................##......
+.....#..................#......#........#.................................................#..#........................#..#........
+......#.......#......................................................................#.#.........#....#...........................
+..................#.#........................#......#................................................................#......#.....
+.....................#............#...................#.....#....................................#.......#..........#.......#.....
+#.............................#...............................#...#...............................................................
+..##.........#........#......................................#.....................#...#.............#............#..#............
+..........#.....................#..#....................#...#....................#....................#.....................#.....
+...........#..........#...............#..#..........#..............................................#.#............................
+............#...#...#.............#.........#.............................#...............#.......................................
+.........#...........#...............................................................#............................................
+.#..#.................................................................#............#.#.......................##...................
+........##............#...................#................................#......................................................
+............................................#..........................#..........................................................
+#...................#...........#..............#...#............#.#........#.................#......#.............................
+........#....................................#....................................................................................
+...........#.........#..#...............#...........#.....##.#......#....##............#....#....#.#.........##.........#.........
+..#......................#..........#.................#.................#......#.............................#........#...........
+....................#.................#....#..............................#....#.............#....#....#.....................#....
+............#.................#.................................#...............................#..#...........................#..
+...................................................#.....#..............#.......#....................#.#..........................
+..#.........##..#........#...................................................................................#............#.......
+.....#..............................#......................................................................#........#.............
+................................#........##.......#...............#..............#.......#...#.#........#.........................
+..............................#.....................#.........................................#..................................#
+...........#...................##.................#.................................#...............................#........#....
+..............................#...##......#..................#...#................................#......#.......#...............#
+.....................##......#......#.#.......#..............#......#.................#.........#...................#.............
+..........................#................................#...........#..........................................................
+...#.....#....................#.....................#...#.....#.............................#.#....#.....#.#.................#....
+............................#...#........#......................................................................#.....#...........
+............#..........##..................#.............................................................#.....#..#...............