🏡 index : ~doyle/aoc.git

author Jordan Doyle <jordan@doyle.la> 2024-12-30 1:48:34.0 +07:00:00
committer Jordan Doyle <jordan@doyle.la> 2024-12-30 1:55:56.0 +07:00:00
commit
cacf55869788eaff1f7458d4798fa35d38c57a0b [patch]
tree
47f9ba30e7e0626e417bcd05ae74016d10497b58
parent
a201f57d1303aa22940c2c6694ae4e587b51c58a
download
cacf55869788eaff1f7458d4798fa35d38c57a0b.tar.gz

Add 2024 day 25



Diff

 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::<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
}