From 00000340e7430f2737daaa8e654fc25afcf97a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Thu, 2 Jan 2025 22:45:07 +0100 Subject: [PATCH] solution: day 25 --- data/examples/25.txt | 39 ++++++++++++++++++++++++++++++ src/bin/25.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 data/examples/25.txt create mode 100644 src/bin/25.rs diff --git a/data/examples/25.txt b/data/examples/25.txt new file mode 100644 index 000000000..8e29855 --- /dev/null +++ b/data/examples/25.txt @@ -0,0 +1,39 @@ +##### +.#### +.#### +.#### +.#.#. +.#... +..... + +##### +##.## +.#.## +...## +...#. +...#. +..... + +..... +#.... +#.... +#...# +#.#.# +#.### +##### + +..... +..... +#.#.. +###.. +###.# +###.# +##### + +..... +..... +..... +#.... +#.#.. +#.#.# +##### diff --git a/src/bin/25.rs b/src/bin/25.rs new file mode 100644 index 000000000..6bba7d8 --- /dev/null +++ b/src/bin/25.rs @@ -0,0 +1,57 @@ +pub fn part_one(input: &str) -> Option { + 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 { + "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)); + } +}