Add 2024 day 25
Diff
Cargo.toml | 4 ++++
README | 4 ++--
2024/25.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 2 deletions(-)
@@ -65,5 +65,9 @@
name = "aoc2024-22"
path = "2024/22.rs"
[[bin]]
name = "aoc2024-25"
path = "2024/25.rs"
[lints.clippy]
pedantic = "deny"
@@ -38,5 +38,5 @@
| 22 | Rust | | 22 | Haskell |
| 23 | Python | | 23 | Haskell |
| 24 | Python | | 24 | Haskell |
+---------------------+ | 25 | Bash |
+---------------------+
| 25 | Rust | | 25 | Bash |
+---------------------+ +---------------------+
@@ -1,0 +1,65 @@
use std::io::Read;
fn main() {
let mut input = String::new();
std::io::stdin().read_to_string(&mut input).unwrap();
let input = parse_input(&input);
part1(&input);
}
fn part1(input: &Input) {
let mut out = 0;
for &(a, b, c, d, e) in &input.keys {
for a in 0..(6 - a) {
for b in 0..(6 - b) {
for c in 0..(6 - c) {
for d in 0..(6 - d) {
for e in 0..(6 - e) {
if input.locks[a][b][c][d][e] {
out += 1;
}
}
}
}
}
}
}
eprintln!("{out}");
}
#[derive(Default, Debug)]
struct Input {
keys: Vec<(usize, usize, usize, usize, usize)>,
locks: [[[[[bool; 7]; 7]; 7]; 7]; 7],
}
#[allow(clippy::many_single_char_names)]
fn parse_input(s: &str) -> Input {
let mut input = Input::default();
for combo in s.split("\n\n") {
let matrix = combo
.split('\n')
.map(|v| v.chars().collect::<Vec<_>>())
.collect::<Vec<_>>();
let count_for = |col| (0..7).filter(|&y| matrix[y][col] == '#').count() - 1;
let a = count_for(0);
let b = count_for(1);
let c = count_for(2);
let d = count_for(3);
let e = count_for(4);
if matrix[0].contains(&'#') {
input.locks[a][b][c][d][e] = true;
} else {
input.keys.push((a, b, c, d, e));
}
}
input
}