Skip to content

Commit 75f6a93

Browse files
committed
2024_25
1 parent 6c5ce03 commit 75f6a93

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/bin/2024_25/main.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use aoc::{common, grid::Grid};
2+
3+
fn solve(input: &str) -> usize {
4+
let mut ans = 0;
5+
let mut rows = 0;
6+
let mut locks = Vec::new();
7+
let mut keys = Vec::new();
8+
for pat in input.split("\n\n") {
9+
let grid = Grid::from_str(pat, |c| c);
10+
rows = grid.rows;
11+
let vec: Vec<usize> = (0..grid.cols)
12+
.map(|c| grid.find_in_col(c, '#').len() - 1)
13+
.collect();
14+
if grid.get(&(0, 0)) == '#' {
15+
// lock
16+
locks.push(vec);
17+
} else {
18+
// key
19+
keys.push(vec);
20+
}
21+
}
22+
23+
for l in locks.iter() {
24+
for k in keys.iter() {
25+
ans += if l.iter().zip(k.iter()).all(|(a, b)| *a + *b < rows - 1) {
26+
1
27+
} else {
28+
0
29+
};
30+
}
31+
}
32+
ans
33+
}
34+
35+
fn main() {
36+
let input = common::get_input();
37+
println!("{input:?}");
38+
common::timed(&input, solve, true);
39+
}
40+
41+
#[cfg(test)]
42+
mod tests {
43+
use super::*;
44+
45+
#[test]
46+
fn test_samples() {
47+
let sample_input = "#####\n.####\n.####\n.####\n.#.#.\n.#...\n.....\n\n#####\n##.##\n.#.##\n...##\n...#.\n...#.\n.....\n\n.....\n#....\n#....\n#...#\n#.#.#\n#.###\n#####\n\n.....\n.....\n#.#..\n###..\n###.#\n###.#\n#####\n\n.....\n.....\n.....\n#....\n#.#..\n#.#.#\n#####";
48+
assert_eq!(solve(sample_input), 3);
49+
}
50+
}

0 commit comments

Comments
 (0)