solution: day 25

This commit is contained in:
Matej Janezic 2025-01-02 22:45:07 +01:00
parent 0000033060
commit 00000340e7
Signed by: janezicmatej
GPG Key ID: 4298E230ED37B2C0
2 changed files with 96 additions and 0 deletions

39
data/examples/25.txt Normal file
View File

@ -0,0 +1,39 @@
#####
.####
.####
.####
.#.#.
.#...
.....
#####
##.##
.#.##
...##
...#.
...#.
.....
.....
#....
#....
#...#
#.#.#
#.###
#####
.....
.....
#.#..
###..
###.#
###.#
#####
.....
.....
.....
#....
#.#..
#.#.#
#####

57
src/bin/25.rs Normal file
View File

@ -0,0 +1,57 @@
pub fn part_one(input: &str) -> Option<usize> {
let mut keys = Vec::new();
let mut locks = Vec::new();
for key_or_lock in input.split("\n\n") {
let lock = key_or_lock
.lines()
.next()
.unwrap()
.chars()
.all(|x| x == '#');
let mut columns = [0; 5];
for (idx, c) in key_or_lock.lines().flat_map(|x| x.chars().enumerate()) {
if c == '#' {
columns[idx] += 1;
}
}
// remove top or bottom row from count
for c in columns.iter_mut() {
*c -= 1;
}
if lock {
locks.push(columns);
} else {
keys.push(columns);
}
}
let mut count = 0;
for k in keys.iter() {
for l in locks.iter() {
if k.iter().zip(l.iter()).all(|(k, l)| k + l <= 5) {
count += 1;
}
}
}
count.into()
}
pub fn part_two(_input: &str) -> Option<String> {
"Happy christmas!".to_string().into()
}
aoc::solution!(25);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_part_one() {
assert_eq!(part_one(&aoc::template::read_file("examples", 25)), Some(3));
}
}