Rust/2024/25: add solution
This commit is contained in:
parent
86de4ac5e2
commit
656311ff36
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
40
Rust/2024/25.rs
Normal 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]);
|
|
@ -23,5 +23,5 @@ aoc::year! {
|
|||
"22.rs",
|
||||
"23.rs",
|
||||
// "24.rs",
|
||||
// "25.rs",
|
||||
"25.rs",
|
||||
}
|
||||
|
|
|
@ -429,3 +429,6 @@ path = "2024/22.rs"
|
|||
[[bin]]
|
||||
name = "2024_23"
|
||||
path = "2024/23.rs"
|
||||
[[bin]]
|
||||
name = "2024_25"
|
||||
path = "2024/25.rs"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue