summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-12-13 00:57:17 -0500
committerJesse Luehrs <doy@tozt.net>2023-12-13 00:57:17 -0500
commit94d4fc2fc3a181bd79f92eb6d93c833e88e6e802 (patch)
tree89b0f147bfb7f288953d36189de8f677db2b6300
parent747edc0066c138718c86ed7cdb9d1685b2ca81a7 (diff)
downloadadvent-of-code-94d4fc2fc3a181bd79f92eb6d93c833e88e6e802.tar.gz
advent-of-code-94d4fc2fc3a181bd79f92eb6d93c833e88e6e802.zip
day 13
-rw-r--r--benches/2023.rs5
-rw-r--r--data/2023/13.txt1339
-rw-r--r--src/bin/2023/day13.rs102
-rw-r--r--src/bin/2023/main.rs2
-rw-r--r--src/grid.rs8
5 files changed, 1456 insertions, 0 deletions
diff --git a/benches/2023.rs b/benches/2023.rs
index d6daad9..211b2f4 100644
--- a/benches/2023.rs
+++ b/benches/2023.rs
@@ -25,6 +25,8 @@ mod day10;
mod day11;
#[path = "../src/bin/2023/day12.rs"]
mod day12;
+#[path = "../src/bin/2023/day13.rs"]
+mod day13;
// NEXT MOD
day!(2023, 1, day1);
@@ -39,6 +41,7 @@ day!(2023, 9, day9);
day!(2023, 10, day10);
day!(2023, 11, day11);
day!(2023, 12, day12);
+day!(2023, 13, day13);
// NEXT DAY
fn bench_2023(c: &mut criterion::Criterion) {
@@ -56,6 +59,7 @@ fn bench_2023(c: &mut criterion::Criterion) {
day_combined!(2023, 10, day10);
day_combined!(2023, 11, day11);
day_combined!(2023, 12, day12);
+ day_combined!(2023, 13, day13);
// NEXT DAY COMBINED
})
});
@@ -76,5 +80,6 @@ criterion::criterion_main!(
bench_2023day10,
bench_2023day11,
bench_2023day12,
+ bench_2023day13,
// NEXT GROUP
);
diff --git a/data/2023/13.txt b/data/2023/13.txt
new file mode 100644
index 0000000..83d53a2
--- /dev/null
+++ b/data/2023/13.txt
@@ -0,0 +1,1339 @@
+.###...####..
+###...#....#.
+###...#....#.
+.###...####..
+###.#........
+#####.#....#.
+##.#..######.
+####.#..##..#
+..#....####..
+#.##.##.##.##
+#.#...#.##.#.
+.###.##.##.##
+#.#....#..#..
+..###.##..##.
+##.#..#....##
+
+....#..#####...
+....#.##.#..##.
+......#.#.###..
+.##........##.#
+######..#..#.#.
+....#.#.#.#..#.
+#..##...#...###
+.##..###.######
+.##..#.#.#....#
+.##...####.#.##
+.....#....#####
+.....#....#####
+.##...######.##
+.##..#.#.#....#
+.##..###.######
+#..##...#...###
+....#.#.#.#..#.
+
+.#..#..####
+.#....#.###
+...#####..#
+##..#.#.###
+.####.###..
+.#.#..#####
+##.##..##..
+##.##..##..
+.#.#..#####
+
+#..##...###
+#..##..#...
+#..##..#...
+#..##...###
+#####..#.##
+#.##..#####
+#..####.#.#
+.##.#.#.#..
+.....#####.
+####..#####
+#..#.#.###.
+#..#.#..#.#
+#..#.##....
+
+....#.#
+####.##
+....#..
+...##..
+.##....
+......#
+.##....
+######.
+.##..#.
+#..#..#
+####.##
+.##...#
+.##...#
+####.##
+#..#..#
+.##..#.
+######.
+
+..##..##.....#...
+.##.#..###..#..#.
+###...###.#...##.
+#..#.###...#.###.
+#..#.###...#.###.
+###...###.#..###.
+.##.#..###..#..#.
+..##..##.....#...
+#..#..#.#.#.#.##.
+#.#..##.##..#.#.#
+##....####.####..
+##.###.#.#.#####.
+##.###.#.#.#####.
+
+##..##.
+#.#.##.
+#.#.##.
+##..##.
+###.#.#
+.#.#..#
+..#...#
+..##...
+.##...#
+.##.#.#
+.##.#.#
+.##.#.#
+..##...
+
+##########....##.
+##.#..#.###.#.##.
+...####...##..##.
+#.######.#.##....
+##.####.###.#...#
+##......##.#.#..#
+.#..##..#.##.#..#
+##..##..###.##..#
+#...##...########
+....##....####..#
+..######..#.##..#
+...#..#....#..##.
+.#.#..#.#.####..#
+
+.##..##
+#.#####
+..#.###
+#.###..
+####...
+#####..
+#.###..
+..#.###
+#.#####
+.##..##
+...#...
+
+.##...#..##.##.
+.#.#######..#..
+.##..##.##.#.##
+.##.##.#..###.#
+.##.##.#..###.#
+.##..##.##.#.##
+.#.#######..#..
+.##...#..##..#.
+..######.###...
+##.#.#.##.#..#.
+#.#...####.#...
+#.#...####.#...
+##.#.#.##.#..#.
+
+.##.##.##....
+....#.##.####
+....#.##.####
+.##.##.##....
+####.#.##....
+....#.###.#.#
+.#.#.###.....
+###.#....####
+.##.####..###
+.##.####..###
+###.#....####
+.#.#.###.....
+..#.#.###.#.#
+####.#.##....
+.##.##.##....
+
+#.##....#.#.#
+#..#.######..
+...##..###.##
+....#..###.##
+#..#.######..
+#.##....#.#.#
+.#.....#.##..
+....#.##..#.#
+....#.##..#.#
+.#.....#.##..
+#.##....#.#.#
+#..#.######..
+....#..###.##
+
+#.##...#.....
+.##.###.#..#.
+##..#.##..##.
+.#.#.#...####
+..#.###.##.#.
+###.##.####.#
+###.##.####.#
+..#.###.##.#.
+.#.#.#...####
+##..#.##..##.
+.##.###.#..#.
+#.##.#.#.....
+.#.###...#.##
+.....##.##.#.
+.....##.##.#.
+.#.###...#.##
+#.##.#.#.....
+
+#...###.#
+##.#..##.
+.##..#..#
+#....###.
+#....###.
+.##..#..#
+##.#..##.
+#...###..
+#...###..
+##.#..##.
+.##..#..#
+
+##.#..##..#.###
+###........###.
+###........###.
+##.#..##..#.###
+##.#..##..#..#.
+..##.####.##...
+..............#
+..##..##..##..#
+###........###.
+##....##....###
+####..##..#####
+#...##..##...#.
+#..##.##.##..#.
+
+####.##
+...#.##
+...#.##
+.###.##
+#.#....
+#..#...
+####.##
+.#..###
+##..###
+##.#.##
+..##.##
+
+###.###..###.##
+..############.
+...#..####..#..
+..#.########.#.
+....##.##.##...
+..##.##..##.##.
+##.#........#.#
+...#..####..#..
+##.#..####..#.#
+##.##......##.#
+##...#.##.#...#
+.....#.#..#....
+#####.#..#.####
+##.#.##..##.#.#
+##..########..#
+##..#.####.#..#
+....#.#..#.#...
+
+#.#.#.####.
+##...#.....
+.##......##
+.##......##
+##...#.....
+#.#.######.
+#....#.....
+##.########
+...##.....#
+.#.#.#.....
+.#.#.#.....
+
+##.###..#.#
+#..###..#.#
+.#...###.#.
+..##...#..#
+###.#..###.
+###.#..###.
+..##...#..#
+
+..#.#..
+..#.#..
+.##....
+.##..#.
+..#...#
+####.#.
+#.#....
+##.#...
+##.#...
+#.#....
+####.#.
+..#.#.#
+.##..#.
+
+###..##
+.##..#.
+#####..
+#####..
+.##..#.
+###..##
+..#####
+.#.####
+.#..###
+
+.#....##....#
+.#.##.##.##.#
+#.#..#..#..#.
+...##....##..
+##....##....#
+#.#..#..#..#.
+#............
+..###....###.
+###..####..##
+##....##....#
+..#..#..#..#.
+###..####..##
+##.##.##.##.#
+
+.........##.###
+.........##.###
+###.#.#..#....#
+......#...###.#
+#.#......##.##.
+.##.######...#.
+#######....####
+######.##.....#
+#.#...##..#####
+####..##..#..##
+##.######.#.#.#
+##...##..###...
+...#.....#.###.
+...#.......###.
+##...##..###...
+
+......#....#..#..
+..##......#....#.
+...#.###.########
+.....##.#........
+.##....#.........
+..###..##........
+..#.##...########
+###..##.#.#.##.#.
+###..##.#.######.
+
+....#...#.#..
+##...####...#
+#.##...#.##..
+#.##...#.##..
+##...####...#
+....#...#.#..
+##...#..#.#.#
+#.#.#.#..####
+#.#..##..##.#
+.####.#.#....
+###...##.##..
+###..###.##..
+.####.#.#....
+
+...####
+..#.##.
+....##.
+##....#
+##.##..
+##.##..
+##....#
+..#.##.
+..#.##.
+...####
+...###.
+..#..##
+..#.###
+##..#.#
+..##.#.
+##.#.##
+...#..#
+
+#....#...#.#.##.#
+##..##...###.#.##
+##..###...#......
+.####.#.##.##...#
+......#.#...##..#
+#....###.#.####.#
+.......##...#...#
+######.#.#...###.
+.#..#.##..##...#.
+.#..#..##...#...#
+.#..#..##...#.#.#
+
+.#.#..#
+.#.#..#
+#.##...
+#...##.
+.#.####
+.#..##.
+.#..##.
+####..#
+##.....
+
+#....#...
+.#...#..#
+.#...#..#
+#....#...
+.#....##.
+..#######
+..#####.#
+.#....##.
+#....#...
+
+.###..###
+.#.###.##
+#.#.#.###
+.##..##..
+#........
+#.#.##.##
+.####.###
+.##......
+.##..#.##
+#.###..##
+.####..##
+....##...
+###..##..
+.##..##..
+....##...
+
+..#..##
+..#..##
+..#...#
+#...###
+###.#.#
+#.#.#..
+.#.#.##
+.#.#.#.
+#.#.#..
+###.#.#
+#...###
+
+..####..##....##.
+........##....##.
+########.#....#.#
+.#....#.#.####.#.
+#.####.#........#
+##.....###....###
+##....##.##..##.#
+##....##.######.#
+##....###......##
+..####..#.#..#.#.
+##.##.##..#..#..#
+
+#....###.....###.
+#....###.....###.
+.##.#.#...#..####
+######.#..##...##
+..##..###...#.###
+..###..###....###
+.###.#.#.#..#.###
+.###.#.#.#..#.###
+..###..###....###
+..##..###...#.###
+######.#..##...##
+.##.#.#...#..####
+#....###.....##..
+
+#.###....#.#..#
+........###....
+........###....
+#.###....#.#..#
+.#.#..#.#.#...#
+....#.#...#....
+.#.#...#.#...##
+.....#.#.######
+###....##.###.#
+###....##..##.#
+.....#.#.######
+
+#..##..##
+.##..####
+#######..
+.....##..
+.##......
+....###..
+#####..##
+.......##
+##.#...##
+#..#..###
+.....####
+#####....
+#..#.....
+
+#.####.##.#
+#.####.##..
+###..##.#..
+..#.#..#..#
+##.#...#.#.
+#.###..##.#
+#.###...#..
+.#....##.##
+..##.##.#..
+##.##...###
+##.##...###
+..##.##.#..
+.#....##.##
+#.###...#..
+#.###..##.#
+
+.###..###....
+...#.#..#..##
+...##........
+...##........
+...#.#..#..##
+.###..###....
+#.#.#.#.#####
+......###.##.
+#.####...#...
+#.###.##.....
+#.....##...##
+.#..#.#...#..
+#..#.##.###..
+
+.#.#.##..#.#####.
+.#.#.##..#.#####.
+..##.#.###.#..##.
+#.####..#....###.
+#.#.##.##.####.#.
+.###..#...#..#..#
+.##...#...#..#..#
+#.#.##.##.####.#.
+#.####..#....###.
+
+####...
+....#..
+...##..
+#..#.##
+#..#..#
+....##.
+....##.
+
+###.#........
+###.#........
+.....###..###
+.#.##.##..##.
+.##...#.##.#.
+##..#..####..
+#..#.#.####.#
+#..####....#.
+#....#..##..#
+.#.###......#
+.#.#.#......#
+.#.####.##.##
+#.####.#..#.#
+......######.
+##.####.##.##
+..###.##..##.
+#####.######.
+
+.#.##..####..##
+#...#.#.##.#.#.
+#...#..####..#.
+#...#..####..#.
+#...#.#.##.#.#.
+.#.##..####..##
+#..#...####...#
+.###...####...#
+#.##..##..##..#
+#..##.##..##.##
+#.##.###..###.#
+..#...##..##...
+.#.#....##....#
+.##..#..##..#..
+##...#......#..
+.#....#....#...
+##.#....##.#..#
+
+#......######
+..####..#..##
+.##..##..#..#
+#..##..##.###
+#..##..##.###
+.##..##..#..#
+..####..#..##
+#......######
+.##..##.....#
+..#..#..##...
+##.##.##..##.
+....#....#.##
+.#.##.#.#....
+.#.##.#..###.
+.........##.#
+
+#######.##.##
+#.##.#.#.##..
+##..####.....
+..##....###.#
+##..###..#...
+#....#...#...
+......##.....
+
+#..####..#...
+...#..#....##
+....##.....##
+..#....#..#..
+....##......#
+..#....#..###
+##..##..##.#.
+..##..##.....
+...#..#...###
+###....###...
+............#
+..######...#.
+............#
+...####....#.
+############.
+
+.##.#####..
+##.....#.#.
+##..###.###
+..#.#.#...#
+###....#...
+###......#.
+.##......#.
+####..#####
+####..#####
+.##......#.
+###......#.
+
+##.....##.....###
+.####..##..####..
+#.#.#.####.#.#.##
+....##.##.##.....
+#####......######
+#..#..#..#..#..##
+#.####.##.####.##
+.###..#..#..###..
+#..###.##.###..##
+###.#..##..#.####
+#.#..#####...#.##
+#.#.#.#..#.#.#.##
+.##.#..##..#.##..
+
+###.##....#
+..#####..##
+..##.##..##
+###.##....#
+...#.......
+.#.#.#....#
+.#..#######
+##.##......
+###..#....#
+
+#.#..#..#
+.######..
+###..###.
+..#..#...
+#.####.#.
+#..##..#.
+#.#..#.##
+.#.##.#.#
+###..###.
+#.#..#.##
+#......##
+#......##
+#......##
+#......##
+#.#..#.##
+
+..##..####.#.#.
+..##..####.#.#.
+.#.#.##.##...##
+##.#....#.##..#
+...#...###.#.##
+..##.#.#.#...##
+..#.##..##..#.#
+##..#####.....#
+...##.##.##.#..
+...#.##.##.##.#
+####.#.####.#.#
+
+.####.#..
+.####.#..
+..#.###..
+.##.##.##
+..###.###
+###..#.#.
+.##....##
+##.#.#.#.
+##.#.#.#.
+.##....##
+###..#.#.
+...##.###
+.##.##.##
+..#.###..
+.####.#..
+
+..##...##
+.#..#.#.#
+#....###.
+######..#
+........#
+######.#.
+#.##.####
+..##.....
+##..##..#
+......##.
+.####.#.#
+######.##
+.#..#..##
+.#..#...#
+######.##
+
+##########..##...
+#..#..#..#....##.
+...#..#....##....
+....##....#.#..#.
+.##.##.##....#.##
+.##.##.##.##..###
+..........#..###.
+
+#####..#####.##.#
+#.##....##.#.....
+#...#..#...#..##.
+#.###..###.#.....
+.#..####..#.#####
+##..####..###.##.
+##...##...###.##.
+#..######..#.....
+#..######..#.####
+.#..####..#......
+...##..##...#.##.
+#.#.#..#.#.##....
+.###....###..#..#
+.##.#..#.##.#....
+#####..#####.....
+
+#.#.##.###.#...
+##.....#.##.###
+...#.##....#...
+#......####.###
+##.....####.###
+...#.##....#...
+##.....#.##.###
+#.#.##.###.#...
+#######..#...##
+.##.#..#.###...
+..#.#.#########
+
+#..##....####....
+#..##....###.....
+.###########.....
+...##.#.#....###.
+....##..#.#..#.##
+....##..#.#..#.##
+...##.#.#....###.
+.###########.....
+#..##....###.....
+#..##....####....
+.#.#.#..#.#......
+..#.####..##..#.#
+....#..##.#..#...
+
+##........###
+####....####.
+###.#..#.####
+..###..###..#
+..##....##..#
+.##########..
+###.#..#.####
+..###..###...
+..#..##..#..#
+
+#.##..##.#.#.#.
+.#..##..#.###.#
+.#..##..#.###.#
+#.##..##.#.###.
+#.######.###.##
+...#..#...#####
+#..#..#..##....
+#.##..##.#.#.#.
+..######..###.#
+
+#.######.##.#
+##..##...##..
+#....#.##..##
+.##....#....#
+..#....#....#
+#....#.##..##
+##..##...##..
+#.######.##.#
+#.##.###....#
+
+..##.##..
+####.#..#
+#.#...#..
+..#......
+.##......
+#.#...#..
+####.#..#
+..##.##..
+.###.#.##
+#..##....
+.###..###
+...####..
+#####.##.
+#..#.##.#
+#..#.##.#
+
+..#.#..######
+#..#..###.#..
+#..####.#..#.
+##..##.....##
+...###...#.##
+###.#....####
+######.##.#..
+.##.###.##.##
+.##.#.#######
+.#.#.#..##...
+.#.#####.####
+.#.#####.####
+.#.#.#..##...
+
+#...#..#...#.#.
+#...##.##..###.
+.##.#...##.#...
+.##.#...##.#...
+#...##.##..###.
+#...#..#...#.#.
+##.#...###.####
+...#.#.#.##....
+#.#...######.#.
+#..##...#####.#
+.###.#.###.#.##
+.###.#.###.#.##
+#..##...#####.#
+#.#...####.#.#.
+...#.#.#.##....
+##.#...###.####
+#...#..#...#.#.
+
+..##...#.#..###
+..##...#.###...
+.#..#....###.#.
+....#..#..#.###
+.......##.##.#.
+##..##...#.##..
+#######.#.##..#
+#######.#.##..#
+##..##...#.##..
+.......##.##.#.
+....#..#..#.###
+
+.##...#.#####
+.##.#.#.#.###
+###.#.#.#.###
+.##...#.#####
+....#..#..#..
+#######..##..
+###.....#.#..
+###...#.###..
+#.#..#.###...
+.###.#.#..#..
+#.##.##.#..##
+
+#...#..##.###
+#.#.#.##.#..#
+##.##..#..#..
+####.#..##.##
+...##.#.##.##
+##.#....#.#..
+#..##.#...#..
+#..#.##.#....
+..#........##
+..#........##
+#..#.##.#....
+
+######.#..##.##.#
+..#######.#...##.
+.#####.#.#.#...##
+#.##..#.######...
+.##..#..#.#..####
+.###..###..##...#
+#...######..#.###
+####.#.#..##..#.#
+####.#.#..##..#.#
+#...######..#.###
+.###..###..##...#
+.##..#..#.#..####
+#.##..########...
+.#####.#.#.#...##
+..#######.#...##.
+######.#..##.##.#
+######.#..##.##.#
+
+#.##..##.####
+..#.##.#.....
+###.##.######
+#.#....#.####
+#.##..##.####
+..#....#..##.
+.########.##.
+.###..###.##.
+#..####...##.
+#..#..#..#..#
+##......#####
+####..####..#
+..#.##.#.....
+..#.##.#..##.
+###.##.###..#
+..##..##..##.
+.###..###.##.
+
+##....###.#######
+##....###..######
+.##.#.##..###.#.#
+###..####.#.#####
+##.########..#.##
+#.##.##...#.#.##.
+.#...#.........#.
+.#...#.........#.
+#.##.##...#.#.##.
+##.########..#.##
+###..####.#.#####
+.##.#.##..###.#.#
+##....###..######
+##....###.#######
+.###..###########
+###..##..##..###.
+#.#....#..#.#.###
+
+#.##..#
+..#....
+.###..#
+#...##.
+.#.####
+.#.####
+#...##.
+.###..#
+..#....
+#.##..#
+#.#####
+#.###.#
+##.#..#
+
+.#.#.####.#.##.##
+...#.####.#.##.##
+....#....#...#.##
+#..##.##.###...#.
+#..##..#......#.#
+.###..#.##.#.####
+.#...#.##.##.##.#
+#..##.##.#..#..#.
+#.....##.#.######
+..##....#..#...##
+.....#.#...#....#
+.....#.#...#....#
+..##....#..#...##
+
+####..#
+...####
+.##....
+###....
+..#.##.
+###.##.
+###.##.
+..#.##.
+#.#....
+
+..#.#....#.#.
+##...#..#...#
+....#.##.....
+..#...##...#.
+..##########.
+###.##..##.##
+####......###
+..#........#.
+##.########.#
+
+#.#.##...####..#.
+.#####.###.#.####
+....###.##.......
+.###.#.#..##.#.#.
+##.#.###.##..###.
+##.#.###.##..###.
+.###.#.#..##.#.#.
+....###.##.#.....
+.#####.###.#.####
+#.#.##...####..#.
+.#..##.....####.#
+#.##...#.##..####
+#.##...#.##..####
+.#..##.....####.#
+#.#.##...####..#.
+
+..##..#.#..#.##
+..#.#..##..####
+##.#...###....#
+..####.#.#.#.##
+..####.#.#.#.##
+##.#...###....#
+..#.#...#..####
+..##..#.#..#.##
+.....##.#...#..
+####...##...###
+..#...##...####
+##.....#.#..###
+##...####..##..
+..##.#####.##.#
+##.#.##..#.#.##
+..##......#.#..
+....#..#.####..
+
+.#.####
+####.#.
+##.###.
+..##..#
+##..#.#
+...#.#.
+####..#
+####..#
+...#.#.
+
+##......#.....#..
+.#.###..##..#..#.
+....###.#.######.
+..##.###....#####
+##.#.#.##..######
+...#######.#..###
+..#...#.##.#..###
+..#...#.##.#..###
+...#######.#..###
+
+.##.###
+.#..###
+.##.#..
+###.#.#
+.#.#..#
+#.####.
+##..#.#
+#.###.#
+######.
+#.####.
+#....#.
+#....#.
+#.####.
+
+##..##..##..###
+#....#..#....##
+..#.#.##.#.#...
+#####.##..#####
+###.##..##.####
+#.....##.....##
+#####.##.######
+
+.#..##.#..#
+####.##.##.
+...##.#.##.
+#.#....##..
+##..#######
+.#.#..#..##
+.#.#..#.###
+.........#.
+##..#......
+##..#......
+.........#.
+.#.#..#.###
+.#.#..#..##
+
+.##..#.##........
+##..##....##..##.
+##.###....##..##.
+.##..#.##........
+.###..##.###..###
+...##..#...####..
+##.#.##.#.#....#.
+#####..##..#..#..
+...##.###.#.##.#.
+##.#...###.####.#
+.#..##.#...#..#..
+....####....##...
+...#..##.###..###
+
+#..######.##.##
+....#..###..###
+....#..###..###
+#..######.##.##
+##.###..######.
+#......#.#..#.#
+.#.#.##########
+##.###.#......#
+####.####.##.##
+#...##..#######
+#...#.####..###
+
+.#......#.#
+..#.##.#..#
+#..#..#..#.
+.##.##.##..
+.#......#..
+##......###
+.#.#..#.#..
+....##....#
+##......###
+#..#..#..#.
+#..####..##
+..........#
+##.#######.
+..#.##.#..#
+..#.##.#..#
+
+..######..###
+###....####..
+####..####...
+.#.####.#...#
+#.#....#.#...
+#........#...
+#........#...
+##......##...
+#........#...
+
+.#..####...##.##.
+##.#.#.#...#.##.#
+####.##..#.##..##
+#.....#.#..##.##.
+#####.#####.####.
+#####.#####.####.
+#.....#.#..##.##.
+####.##..#.##..##
+##.#.#.#...#.##.#
+.#..####...#####.
+.#.##..###.#..#..
+#..#.#..#....#.#.
+#.##..####..#.##.
+##..##.#.###.#.##
+##..##.#.###.#.##
+#.##..####..#.##.
+#..#.#..#....#.#.
+
+...#.##..####
+.#.#...#..#.#
+#.#########.#
+#.#..##..#...
+####..#.###.#
+####....###.#
+#.#..##..#...
+#.#########.#
+.#.#...#..#.#
+...#.##..####
+......#..#..#
+......#..#..#
+...#.##..####
+
+.....##..##......
+...##.....###...#
+#.#.########.#.#.
+.####..##..####.#
+#####.####.#####.
+#####.####.#####.
+.####..##..####.#
+
+#..#..##..#
+....#....#.
+#..#..##..#
+.....####..
+.##........
+.....####..
+....######.
+.##.##..##.
+#....#..#..
+....##..##.
+.##.#....#.
+
+...##....#.##..##
+#...#.#..##......
+.##.##..#...##...
+.###.#.....#.#...
+##.#...#.#.##.#.#
+##.#...#.#.##.#.#
+.###.#.....#.#...
+.##.##..#...##...
+#...#.#..##......
+...##....#.##..##
+.#...#.#.#.###...
+...#.###..#....##
+...#.####.#....##
+
+##.##..###.#.
+##.##..###.#.
+..##..#......
+#..##.#######
+###.##.#....#
+..#.###..##..
+#.#.#.#......
+.....####..##
+.....####.###
+#.#.#.#......
+..#.###..##..
+
+###..##
+###..##
+.#.#.##
+.##.#.#
+##..###
+.#..###
+..#.#..
+.####..
+.##..##
+.##.#..
+#.###..
+
+#......####.##.##
+..##.##..###..###
+..##..#..###..###
+#......####.##.##
+#..###.###......#
+..#.#...####..###
+..#..#####.#..#.#
+.##.#.#..##....##
+...#.####..#..#..
+##.#..#.#..####..
+#.#.#.#.##......#
+
+.##.#####.##...
+.#.#.##..###.##
+.#.#.##..###.##
+.##.########...
+###.##.#.##.###
+#####..#.#...##
+....##...#.####
+.##.##.#.#.####
+#.#..#######.##
+
+###..###..##.
+..####..#....
+#.#..#.#.####
+#.#..#.###..#
+###..########
+#.####.#####.
+##.##.##.....
+.##..##.#....
+#.#..#.##....
+.#....#......
+.#....#.#.##.
+
+#..#.##.#..####..
+.#........#.#..#.
+.####..####..##..
+###.#..#.#####.##
+#..........###...
+#..........###...
+###.#..#.#####.##
+.####..####..##..
+.#........#.#..#.
+#..#.##.#..####..
+#.#..##.##.####.#
+
+##.###..##.
+##.##...##.
+..##....#.#
+###.####.##
+...####.###
+###.##.#.#.
+##.###.#...
+
+###.#####..
+#######...#
+##..##.##.#
+.#..#..#.#.
+..##..#.#..
+#.##.#..##.
+##..##.#...
+........#..
+#.##.######
+.####....#.
+######....#
+######....#
+.####....#.
+
+#..###.#.
+###..##..
+...#.##.#
+#..#..###
+#..#..###
+...#.##.#
+###..##..
+#..###.#.
+.#.#####.
+#..##.#..
+.#.#.#...
+.#.#.#.##
+###.#..##
+##...##.#
+.#...##.#
+
+....###.##.
+.##..#####.
+....#...#.#
+.##.....##.
+.....###..#
+......#.###
+......#.###
+.....###..#
+.##.....##.
+....#...#.#
+.##..####..
+....###.##.
+#..##.#....
+#####.#.###
+.##.#####..
+.....#..#..
+.##.#..#..#
+
+.#.##.#..#.##.#.#
+#.####....####.##
+###..######..####
+#.....##.#.....#.
+#....#.##.#....#.
+####.######.####.
+...####..####...#
+#...#.####.#...##
+#...#.####.#...##
+...####..####...#
+####.######.####.
+
+###..#..#..######
+#.#...##...#.##.#
+##..#.##.#..####.
+...##....##......
+#.##.#..#.##.##.#
+####..##..#######
+#.#.##..##.#.##.#
+#.####..####.##.#
+##.###..###.####.
+.###......###..##
+#.#..####..#.####
+##..#....#..####.
+.#.#.#..#.#.#..#.
+###..#..#..######
+.##.#.##.#.##..##
+#.#.#....#.#.##.#
+#..#..##..#..##..
+
+.#..##..#.#..#.#.
+.#..##..#......#.
+#..###...##..##..
+.##.##.##..##..##
+.#.####.#..##..#.
+..#....#..#..#..#
+.##.##.##.#..#.##
+#.#.##.#.#.##.#.#
+###....##########
+##.#..#.###..###.
+...#..#...#..#...
+#.##..##.#....#.#
+.##.##.##.#..#.##
diff --git a/src/bin/2023/day13.rs b/src/bin/2023/day13.rs
new file mode 100644
index 0000000..a5579b8
--- /dev/null
+++ b/src/bin/2023/day13.rs
@@ -0,0 +1,102 @@
+#![allow(dead_code)]
+#![allow(unused_variables)]
+
+use advent_of_code::prelude::*;
+
+enum Mirror {
+ Horizontal(usize),
+ Vertical(usize),
+}
+
+impl Mirror {
+ fn score(&self) -> usize {
+ match self {
+ Self::Horizontal(n) => 100 * n,
+ Self::Vertical(n) => *n,
+ }
+ }
+}
+
+fn find_mirror(pattern: &Grid<bool>, smudges: usize) -> Mirror {
+ 'mirror: for row in pattern.each_row().skip(1) {
+ let mut found_smudges = 0;
+ for offset in 0..row.min(pattern.rows() - row.0).0 {
+ let a = pattern.row_vec(row + offset);
+ let b = pattern.row_vec(row - offset - 1);
+ found_smudges += a
+ .into_iter()
+ .zip(b.into_iter())
+ .filter(|(a, b)| a != b)
+ .count();
+ if found_smudges > smudges {
+ continue 'mirror;
+ }
+ }
+ if found_smudges != smudges {
+ continue 'mirror;
+ }
+ return Mirror::Horizontal(row.0);
+ }
+
+ 'mirror: for col in pattern.each_col().skip(1) {
+ let mut found_smudges = 0;
+ for offset in 0..col.min(pattern.cols() - col.0).0 {
+ let a = pattern.col_vec(col + offset);
+ let b = pattern.col_vec(col - offset - 1);
+ found_smudges += a
+ .into_iter()
+ .zip(b.into_iter())
+ .filter(|(a, b)| a != b)
+ .count();
+ if found_smudges > smudges {
+ continue 'mirror;
+ }
+ }
+ if found_smudges != smudges {
+ continue 'mirror;
+ }
+ return Mirror::Vertical(col.0);
+ }
+
+ unreachable!()
+}
+
+pub fn parse(fh: File) -> Result<Vec<Grid<bool>>> {
+ let mut lines = parse::raw_lines(fh).peekable();
+ let mut grids = vec![];
+ while lines.peek().is_some() {
+ grids
+ .push(parse::grid(parse::chunk(&mut lines), |c, _, _| c == b'#'));
+ }
+ Ok(grids)
+}
+
+pub fn part1(patterns: Vec<Grid<bool>>) -> Result<i64> {
+ Ok(patterns
+ .into_iter()
+ .map(|pattern| find_mirror(&pattern, 0).score())
+ .sum::<usize>()
+ .try_into()
+ .unwrap())
+}
+
+pub fn part2(patterns: Vec<Grid<bool>>) -> Result<i64> {
+ Ok(patterns
+ .into_iter()
+ .map(|pattern| find_mirror(&pattern, 1).score())
+ .sum::<usize>()
+ .try_into()
+ .unwrap())
+}
+
+#[test]
+fn test() {
+ assert_eq!(
+ part1(parse(parse::data(2023, 13).unwrap()).unwrap()).unwrap(),
+ 37975
+ );
+ assert_eq!(
+ part2(parse(parse::data(2023, 13).unwrap()).unwrap()).unwrap(),
+ 32497
+ );
+}
diff --git a/src/bin/2023/main.rs b/src/bin/2023/main.rs
index 591fdc8..2ee1dc4 100644
--- a/src/bin/2023/main.rs
+++ b/src/bin/2023/main.rs
@@ -23,6 +23,7 @@ mod day9;
mod day10;
mod day11;
mod day12;
+mod day13;
// NEXT MOD
#[paw::main]
@@ -41,6 +42,7 @@ fn main(opt: Opt) -> Result<()> {
10 => advent_of_code::day!(2023, opt.day, opt.puzzle, day10),
11 => advent_of_code::day!(2023, opt.day, opt.puzzle, day11),
12 => advent_of_code::day!(2023, opt.day, opt.puzzle, day12),
+ 13 => advent_of_code::day!(2023, opt.day, opt.puzzle, day13),
// NEXT PART
_ => panic!("unknown day {}", opt.day),
}
diff --git a/src/grid.rs b/src/grid.rs
index f299bee..b006882 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -269,6 +269,10 @@ impl<T: Clone + Eq + PartialEq + std::hash::Hash> Grid<T> {
(0..self.rows().0).map(Row)
}
+ pub fn row_vec(&self, row: Row) -> Vec<T> {
+ self.rows[row.0].cells.clone()
+ }
+
pub fn cols(&self) -> Col {
Col(self.rows[0].cells.len())
}
@@ -280,6 +284,10 @@ impl<T: Clone + Eq + PartialEq + std::hash::Hash> Grid<T> {
(0..self.cols().0).map(Col)
}
+ pub fn col_vec(&self, col: Col) -> Vec<T> {
+ self.rows.iter().map(|row| row[col].clone()).collect()
+ }
+
pub fn get(&self, row: Row) -> Option<&GridRow<T>> {
self.rows.get(row.0)
}