Skip to content

Commit a9e4b90

Browse files
committed
solve: day25
1 parent f6a44e7 commit a9e4b90

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
resolver = "2"
33
members = [
44
"utils",
5-
"aoc_derive", "day1", "day2", "day3", "day4", "day5", "day6", "day7", "day8", "day9", "day10", "day11", "day12", "day13", "day14", "day15", "day16", "day17", "day18", "day19", "day20", "day21", "day22", "day23", "day24",
5+
"aoc_derive", "day1", "day2", "day3", "day4", "day5", "day6", "day7", "day8", "day9", "day10", "day11", "day12", "day13", "day14", "day15", "day16", "day17", "day18", "day19", "day20", "day21", "day22", "day23", "day24", "day25",
66
]
77

88
[workspace.dependencies]

day25/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "day25"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
aoc_derive.path = '../aoc_derive'
8+
utils.path = '../utils'
9+
derive_more.workspace = true
10+
itertools.workspace = true
11+
lazy-regex.workspace = true
12+
parse-display.workspace = true
13+
rayon.workspace = true
14+
regex.workspace = true
15+
num.workspace = true
16+
17+
[dev-dependencies]
18+
pretty_assertions.workspace = true

day25/src/main.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use aoc_derive::aoc_main;
2+
use grid::Grid;
3+
use itertools::iproduct;
4+
use utils::*;
5+
6+
#[aoc_main]
7+
fn solve(input: Input) -> impl Into<Solution> {
8+
let (locks, keys): (Vec<_>, Vec<_>) = input
9+
.blocks()
10+
.map(|block| Grid::<char>::from_iter(block.lines().map(|l| l.chars())))
11+
.partition(|grid| grid.row(0).all(|(_, &c)| c == '#'));
12+
13+
iproduct!(locks, keys)
14+
.filter(|(lock, key)| {
15+
lock.cols().zip(key.cols()).all(|(lhs, rhs)| {
16+
lhs.values().filter(|&&c| c == '#').count()
17+
+ rhs.values().filter(|&&c| c == '#').count()
18+
<= 7
19+
})
20+
})
21+
.count()
22+
}
23+
24+
#[cfg(test)]
25+
mod tests {
26+
use super::*;
27+
#[test]
28+
fn test_examples() {
29+
use utils::assert_example;
30+
assert_example!(
31+
r#"#####
32+
.####
33+
.####
34+
.####
35+
.#.#.
36+
.#...
37+
.....
38+
39+
#####
40+
##.##
41+
.#.##
42+
...##
43+
...#.
44+
...#.
45+
.....
46+
47+
.....
48+
#....
49+
#....
50+
#...#
51+
#.#.#
52+
#.###
53+
#####
54+
55+
.....
56+
.....
57+
#.#..
58+
###..
59+
###.#
60+
###.#
61+
#####
62+
63+
.....
64+
.....
65+
.....
66+
#....
67+
#.#..
68+
#.#.#
69+
#####"#,
70+
3
71+
);
72+
}
73+
}

utils/src/grid.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ impl<'a, T> ColIter<'a, T> {
254254
fn new(grid: &'a Grid<T>, col: usize) -> Self {
255255
ColIter { grid, row: 0, row_back: grid.num_rows(), col }
256256
}
257+
258+
pub fn values(self) -> impl Iterator<Item = &'a T> {
259+
self.map(|(_, val)| val)
260+
}
257261
}
258262

259263
impl<'a, T> Iterator for ColIter<'a, T> {

0 commit comments

Comments
 (0)