-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday25.rs
60 lines (49 loc) · 1.21 KB
/
day25.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
//! [Day 25: Code Chronicle](https://adventofcode.com/2024/day/25)
/// Solve part one.
fn part1(data: &str) -> u64 {
let mut locks = Vec::new();
let mut keys = Vec::new();
for schematics in data.split("\n\n") {
let heights: Vec<_> = (0..5)
.map(|x| {
schematics
.lines()
.filter(|row| row.chars().nth(x).unwrap() == '#')
.count()
- 1
})
.collect();
if schematics.starts_with("#####") {
locks.push(heights);
} else {
keys.push(heights);
}
}
let mut answer = 0;
for key in &keys {
for lock in &locks {
if key.iter().zip(lock.iter()).all(|(a, b)| a + b <= 5) {
answer += 1;
}
}
}
answer
}
/// # Panics
#[must_use]
pub fn solve(data: &str) -> (u64, aoc::Christmas) {
(part1(data), aoc::CHRISTMAS)
}
pub fn main() {
let args = aoc::parse_args();
args.run(solve);
}
#[cfg(test)]
mod test {
use super::*;
const TEST_INPUT: &str = include_str!("test.txt");
#[test]
fn test_part1() {
assert_eq!(part1(TEST_INPUT), 3);
}
}