From 86bac31392a76da84817eec020d2b84d099b3cc1 Mon Sep 17 00:00:00 2001 From: mhsn Date: Wed, 18 Mar 2026 21:48:13 +0000 Subject: add other challenges support --- 2024/07/rust/Cargo.lock | 7 ----- 2024/07/rust/Cargo.toml | 6 ---- 2024/07/rust/src/main.rs | 71 ------------------------------------------------ 3 files changed, 84 deletions(-) delete mode 100644 2024/07/rust/Cargo.lock delete mode 100644 2024/07/rust/Cargo.toml delete mode 100644 2024/07/rust/src/main.rs (limited to '2024/07/rust') diff --git a/2024/07/rust/Cargo.lock b/2024/07/rust/Cargo.lock deleted file mode 100644 index d1897ed..0000000 --- a/2024/07/rust/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "aoc_2024-07" -version = "0.1.0" diff --git a/2024/07/rust/Cargo.toml b/2024/07/rust/Cargo.toml deleted file mode 100644 index c64c1b5..0000000 --- a/2024/07/rust/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "aoc_2024-07" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/2024/07/rust/src/main.rs b/2024/07/rust/src/main.rs deleted file mode 100644 index df586b1..0000000 --- a/2024/07/rust/src/main.rs +++ /dev/null @@ -1,71 +0,0 @@ -use std::io; - -fn main() -> io::Result<()> { - let eqns = io::stdin() - .lines() - .flatten() - .collect::>() - .iter() - .map(|line| line.split_once(": ").unwrap()) - .map(|(ans, nums)| { - ( - ans.parse::().unwrap(), - nums.split_whitespace() - .map(|s| s.parse::().unwrap()) - .collect::>(), - ) - }) - .collect::>(); - - let silver: u64 = eqns.iter().map(crate::silver).sum(); - let gold: u64 = eqns.iter().map(crate::gold).sum(); - - println!("silver: {silver}"); - println!("gold: {gold}"); - - return Ok(()); -} - -fn concat(x: &u64, y: &u64) -> u64 { - x * (10u64.pow(y.ilog10() + 1)) + y -} - -fn calibration(want: u64, x: &u64, y: &u64, rest: &[u64], gold: bool) -> bool { - if *x > want { - return false; - } - match rest { - [] => want == x + y || want == x * y || (gold && want == concat(x, y)), - [z, rest @ ..] => { - calibration(want, &(x + y), z, rest, gold) - || calibration(want, &(x * y), z, rest, gold) - || (gold && calibration(want, &concat(x, y), z, rest, gold)) - } - } -} - -fn silver((want, nums): &(u64, Vec)) -> u64 { - match nums.as_slice() { - [x, y, rest @ ..] => { - if calibration(*want, x, y, rest, false) { - *want - } else { - 0 - } - } - _ => 0, - } -} - -fn gold((want, nums): &(u64, Vec)) -> u64 { - match nums.as_slice() { - [x, y, rest @ ..] => { - if calibration(*want, x, y, rest, true) { - *want - } else { - 0 - } - } - _ => 0, - } -} -- cgit v1.2.3