From cacf55869788eaff1f7458d4798fa35d38c57a0b Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Mon, 30 Dec 2024 01:48:34 +0700 Subject: [PATCH] Add 2024 day 25 --- Cargo.toml | 4 ++++ README | 4 ++-- 2024/25.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8319fad..d24a0d2 100644 --- a/Cargo.toml +++ a/Cargo.toml @@ -65,5 +65,9 @@ name = "aoc2024-22" path = "2024/22.rs" +[[bin]] +name = "aoc2024-25" +path = "2024/25.rs" + [lints.clippy] pedantic = "deny" diff --git a/README b/README index 3a908fe..78d98df 100644 --- a/README +++ a/README @@ -38,5 +38,5 @@ | 22 | Rust | | 22 | Haskell | | 23 | Python | | 23 | Haskell | | 24 | Python | | 24 | Haskell | -+---------------------+ | 25 | Bash | - +---------------------+ +| 25 | Rust | | 25 | Bash | ++---------------------+ +---------------------+ diff --git a/2024/25.rs b/2024/25.rs new file mode 100644 index 0000000..0cef505 100644 --- /dev/null +++ a/2024/25.rs @@ -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::>()) + .collect::>(); + + 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 +} -- rgit 0.1.5