Rust/2024/25: add solution

This commit is contained in:
Felix Bargfeldt 2024-12-25 06:54:46 +01:00
parent 86de4ac5e2
commit 656311ff36
Signed by: Defelo
GPG key ID: 2A05272471204DD3
4 changed files with 46 additions and 3 deletions

File diff suppressed because one or more lines are too long

40
Rust/2024/25.rs Normal file
View file

@ -0,0 +1,40 @@
#![feature(test)]
type Input = Vec<Vec<Vec<bool>>>;
fn setup(input: &str) -> Input {
input
.trim()
.split("\n\n")
.map(|block| {
block
.lines()
.map(|line| line.bytes().map(|b| b == b'#').collect())
.collect()
})
.collect()
}
fn part1(input: &Input) -> usize {
let filtered = |keys| {
input.iter().filter(move |b| b[0][0] ^ keys).map(|b| {
(0..b[0].len())
.map(|i| b.iter().filter(|r| r[i]).count())
.collect::<Vec<_>>()
})
};
let locks = filtered(false).collect::<Vec<_>>();
filtered(true)
.flat_map(|k| {
locks.iter().filter(move |l| {
k.iter()
.zip(l.iter())
.all(|(&k, &l)| k + l <= input[0].len())
})
})
.count()
}
aoc::main!(2024, 25, ex: 1[a]);

View file

@ -23,5 +23,5 @@ aoc::year! {
"22.rs",
"23.rs",
// "24.rs",
// "25.rs",
"25.rs",
}

View file

@ -429,3 +429,6 @@ path = "2024/22.rs"
[[bin]]
name = "2024_23"
path = "2024/23.rs"
[[bin]]
name = "2024_25"
path = "2024/25.rs"