Day 25 (late)

This commit is contained in:
sepia 2024-12-27 02:29:04 -06:00
parent 9a43cb0f4a
commit 4e0f8ed0e6
2 changed files with 26 additions and 1 deletions

23
src/day25.rs Normal file
View File

@ -0,0 +1,23 @@
use crate::util::maps::World;
pub fn day25() {
let keys_and_locks: Vec<World<bool>> = crate::input(25)
.split("\n\n")
.map(|keylock| World::from_string(keylock).map(|&c| c == '#'))
.collect();
let (locks, keys): (Vec<World<bool>>, Vec<World<bool>>) =
keys_and_locks.into_iter().partition(|key_or_lock| {
(0..key_or_lock.width()).all(|x| key_or_lock.get(x, 0) == Some(true))
});
let combos: usize = locks
.iter()
.map(|lock| keys.iter().filter(|key| fits(key, lock)).count())
.sum();
println!("There are {combos} combinations of keys and locks that work.");
}
fn fits(key: &World<bool>, lock: &World<bool>) -> bool {
!key.enumerate()
.any(|(x, y, c)| *c && lock.get(x, y) == Some(true))
}

View File

@ -32,7 +32,9 @@ mod day21;
mod day22;
#[allow(dead_code)]
mod day23;
#[allow(dead_code)]
mod day24;
mod day25;
#[allow(dead_code)]
mod day3;
#[allow(dead_code)]
@ -49,7 +51,7 @@ mod day8;
mod day9;
fn main() {
day24::day24();
day25::day25();
}
pub fn input(day: u8) -> String {