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/03/rust/Cargo.lock | 7 ----- 2024/03/rust/Cargo.toml | 4 --- 2024/03/rust/src/main.rs | 68 ------------------------------------------------ 3 files changed, 79 deletions(-) delete mode 100644 2024/03/rust/Cargo.lock delete mode 100644 2024/03/rust/Cargo.toml delete mode 100644 2024/03/rust/src/main.rs (limited to '2024/03/rust') diff --git a/2024/03/rust/Cargo.lock b/2024/03/rust/Cargo.lock deleted file mode 100644 index a7a6f57..0000000 --- a/2024/03/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-03" -version = "0.1.0" diff --git a/2024/03/rust/Cargo.toml b/2024/03/rust/Cargo.toml deleted file mode 100644 index 97ec307..0000000 --- a/2024/03/rust/Cargo.toml +++ /dev/null @@ -1,4 +0,0 @@ -[package] -name = "aoc_2024-03" -version = "0.1.0" -edition = "2021" diff --git a/2024/03/rust/src/main.rs b/2024/03/rust/src/main.rs deleted file mode 100644 index b268463..0000000 --- a/2024/03/rust/src/main.rs +++ /dev/null @@ -1,68 +0,0 @@ -use std::io::{self, Read}; - -#[derive(Debug)] -enum Instruction { - Do, - Dont, - Mul(u64, u64), -} - -impl From<&Instruction> for u64 { - fn from(val: &Instruction) -> Self { - match val { - Instruction::Mul(x, y) => x * y, - _ => 0, - } - } -} - -fn main() -> io::Result<()> { - let mut program = String::new(); - io::stdin().read_to_string(&mut program)?; - - let instrs = (0..program.len()) - .filter_map(|idx| { - let next = &program[idx..]; - if next.starts_with("do()") { - Some(Instruction::Do) - } else if next.starts_with("don't()") { - Some(Instruction::Dont) - } else if next.starts_with("mul(") { - let mut first = 0; - let mut curr = 0; - - for ch in next.bytes().skip(4) { - match (ch, curr) { - ((b'0'..=b'9'), _) => curr = curr * 10 + (ch - b'0') as u64, - (_, 0) => return None, - (b',', _) => { - first = curr; - curr = 0; - } - (b')', _) => { - return Some(Instruction::Mul(first, curr)); - } - _ => return None, - }; - } - None - } else { - None - } - }) - .collect::>(); - - let silver: u64 = instrs.iter().map(u64::from).sum(); - let (gold, _) = instrs - .iter() - .fold((0 as u64, true), |(acc, on), instr| match (instr, on) { - (Instruction::Do, _) => (acc, true), - (Instruction::Dont, _) => (acc, false), - (Instruction::Mul(_, _), true) => (acc + u64::from(instr), true), - _ => (acc, on), - }); - println!("silver: {silver}"); - println!("gold: {gold}"); - - return Ok(()); -} -- cgit v1.2.3