1
0
This commit is contained in:
2025-07-31 19:47:57 +02:00
parent 06c2ceb96c
commit 20242ad04c
3 changed files with 119 additions and 0 deletions

117
src/day25.rs Normal file
View File

@@ -0,0 +1,117 @@
use std::fs::read_to_string;
use itertools::Itertools;
pub fn day_main() {
let input = read_to_string("input/day25.txt").unwrap();
let input = input.trim();
println!(" part1: {}", part1(input));
}
type RiddleResult = i64;
fn part1(input: &str) -> RiddleResult {
let (locks, keys): (Vec<_>, Vec<_>) = input
.split("\n\n")
.map(|item| {
let block = item
.lines()
.map(|line| line.chars().collect_vec())
.collect_vec();
let lock = block[0].contains(&'#');
let summary: (u8, u8, u8, u8, u8) = if lock {
// lock
(0..5)
.map(|x| {
(0..6)
.map(|y| block[y][x])
.enumerate()
.find(|(_, it)| *it == '.')
.unwrap_or((6, '.'))
.0 as u8
})
.collect_tuple()
.unwrap()
} else {
(0..5)
.map(|x| {
7 - ((0..6)
.map(|y| block[y][x])
.enumerate()
.find(|(_, it)| *it == '#')
.unwrap_or((6, '.'))
.0 as u8)
})
.collect_tuple()
.unwrap()
};
(lock, summary.0, summary.1, summary.2, summary.3, summary.4)
})
.partition(|s| s.0);
let mut matches = 0;
for lock in locks {
for &key in &keys {
if lock.1 + key.1 < 8
&& lock.2 + key.2 < 8
&& lock.3 + key.3 < 8
&& lock.4 + key.4 < 8
&& lock.5 + key.5 < 8
{
matches += 1;
}
}
}
matches
}
#[cfg(test)]
mod test {
use super::part1;
const TEST_INPUT: &str = r"#####
.####
.####
.####
.#.#.
.#...
.....
#####
##.##
.#.##
...##
...#.
...#.
.....
.....
#....
#....
#...#
#.#.#
#.###
#####
.....
.....
#.#..
###..
###.#
###.#
#####
.....
.....
.....
#....
#.#..
#.#.#
#####
";
#[test]
fn test1() {
assert_eq!(part1(TEST_INPUT), 3);
}
}

View File

@@ -19,5 +19,6 @@ pub mod day19;
pub mod day22;
pub mod day23;
pub mod day24;
pub mod day25;
// PLACEHOLDER
pub mod utils;

View File

@@ -27,6 +27,7 @@ fn main() {
(23, day23::day_main),
(23, day23::day_main),
(24, day24::day_main),
(25, day25::day_main),
// PLACEHOLDER
]);
let day: Option<u8> = args().nth(1).and_then(|a| a.parse().ok());