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/09/rust/Cargo.lock | 7 ---- 2024/09/rust/Cargo.toml | 6 --- 2024/09/rust/src/main.rs | 100 ----------------------------------------------- 3 files changed, 113 deletions(-) delete mode 100644 2024/09/rust/Cargo.lock delete mode 100644 2024/09/rust/Cargo.toml delete mode 100644 2024/09/rust/src/main.rs (limited to '2024/09/rust') diff --git a/2024/09/rust/Cargo.lock b/2024/09/rust/Cargo.lock deleted file mode 100644 index 1a4e400..0000000 --- a/2024/09/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-09" -version = "0.1.0" diff --git a/2024/09/rust/Cargo.toml b/2024/09/rust/Cargo.toml deleted file mode 100644 index b440a8b..0000000 --- a/2024/09/rust/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "aoc_2024-09" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/2024/09/rust/src/main.rs b/2024/09/rust/src/main.rs deleted file mode 100644 index fa7c021..0000000 --- a/2024/09/rust/src/main.rs +++ /dev/null @@ -1,100 +0,0 @@ -#![feature(iter_array_chunks)] - -use std::io; - -fn main() -> io::Result<()> { - let disk_map = io::stdin() - .lines() - .flatten() - .next() - .unwrap() - .chars() - .map(|c| c as u8 - b'0') - .collect(); - - let silver: usize = silver(&disk_map); - let gold: usize = gold(&disk_map); - println!("silver: {silver}"); - println!("gold: {gold}"); - - return Ok(()); -} - -fn silver(input: &Vec) -> usize { - let mut blocks = input - .iter() - .chain([0, 0].iter()) // lol - .array_chunks() - .enumerate() - .map(|(n, [&f, &s])| [[Some(n)].repeat(f as usize), [None].repeat(s as usize)]) - .flatten() - .flatten() - .collect::>(); - - let mut l = 0; - let mut r = blocks.len() - 1; - loop { - while blocks[r].is_none() { - r -= 1; - } - while blocks[l].is_some() { - l += 1; - } - if l >= r { - break; - } - let [left, right] = blocks.get_disjoint_mut([l, r]).unwrap(); - left.replace(right.take().unwrap()); - } - - blocks - .iter() - .enumerate() - .map(|(n, id)| n * id.unwrap_or_default()) - .sum() -} - -fn gold(input: &Vec) -> usize { - let mut blocks = input - .iter() - .chain([0, 0].iter()) // lol - .array_chunks() - .enumerate() - .map(|(n, [&f, &s])| [(Some(n), f as usize), (None, s as usize)]) - .flatten() - .collect::>(); - - let mut r = blocks.len(); - while r > 0 { - r -= 1; - let (Some(_), f) = blocks[r] else { - continue; - }; - - // find some empty space and maybe split - let Some(l) = blocks.iter().position(|b| b.0.is_none() && b.1 >= f) else { - continue; - }; - if l > r { - continue; - }; - - let (_, s) = &mut blocks[l]; - - let diff = *s - f; - if diff > 0 { - *s = f; - blocks.insert(l + 1, (None, diff)); - r += 1; - } - blocks.swap(l, r); - } - - blocks - .iter() - .map(|&(id, n)| [id].repeat(n)) - .flatten() - .enumerate() - .map(|(n, id)| n * id.unwrap_or_default()) - .sum() -} -- cgit v1.2.3