diff options
| author | mhsn <mail@mhsn.net> | 2026-03-18 21:48:13 +0000 |
|---|---|---|
| committer | mhsn <mail@mhsn.net> | 2026-03-18 21:48:13 +0000 |
| commit | 86bac31392a76da84817eec020d2b84d099b3cc1 (patch) | |
| tree | e2ee52db59b86b914d5b4bcceb19c9b5d899fff4 /2025/03 | |
| parent | 62fe361fc42dea75deaf7ac31c0ba6ba80e26a9c (diff) | |
| download | puzzles-86bac31392a76da84817eec020d2b84d099b3cc1.tar.gz puzzles-86bac31392a76da84817eec020d2b84d099b3cc1.zip | |
Diffstat (limited to '2025/03')
| -rwxr-xr-x | 2025/03/python.py | 21 | ||||
| -rw-r--r-- | 2025/03/rust/Cargo.lock | 7 | ||||
| -rw-r--r-- | 2025/03/rust/Cargo.toml | 6 | ||||
| -rw-r--r-- | 2025/03/rust/src/main.rs | 42 |
4 files changed, 0 insertions, 76 deletions
diff --git a/2025/03/python.py b/2025/03/python.py deleted file mode 100755 index b0d4bfd..0000000 --- a/2025/03/python.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python3 - -from fileinput import input - -lines = [[int(b) for b in line.strip()] for line in input()] - - -def jolt(bs: list[int], n: int) -> int: - if n == 1: - return max(bs) - n -= 1 - b = max(bs[:-n]) - i = bs.index(b) - return b * (10**n) + jolt(bs[i + 1 :], n) - - -silver = sum(jolt(bs, 2) for bs in lines) -gold = sum(jolt(bs, 12) for bs in lines) - -print("silver:", silver) -print("gold:", gold) diff --git a/2025/03/rust/Cargo.lock b/2025/03/rust/Cargo.lock deleted file mode 100644 index 7f2fe0f..0000000 --- a/2025/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_2025-03" -version = "0.1.0" diff --git a/2025/03/rust/Cargo.toml b/2025/03/rust/Cargo.toml deleted file mode 100644 index c0441da..0000000 --- a/2025/03/rust/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "aoc_2025-03" -version = "0.1.0" -edition = "2024" - -[dependencies] diff --git a/2025/03/rust/src/main.rs b/2025/03/rust/src/main.rs deleted file mode 100644 index be0b3e6..0000000 --- a/2025/03/rust/src/main.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::io; - -fn max(bs: &Vec<u8>, start: usize, end: usize) -> (u8, usize) { - let mut bests = [None; 10]; - for idx in start..=end { - if bs[idx] == 9 { - return (9, idx); - } - bests[bs[idx] as usize].get_or_insert((bs[idx], idx)); - } - bests.into_iter().flatten().last().unwrap() -} - -fn jolt(bs: &Vec<u8>, n: usize) -> u64 { - let mut j: u64 = 0; - let mut start = 0; - for n in (1..=n).rev() { - j *= 10; - let (b, idx) = max(bs, start, bs.len() - n); - j += b as u64; - start = idx + 1; - } - j -} - -fn main() { - let (silver, gold) = io::stdin() - .lines() - .flatten() - .map(|line| { - line.into_bytes() - .iter() - .map(|&x| x - b'0') - .collect::<Vec<u8>>() - }) - .map(|bs| (jolt(&bs, 2), jolt(&bs, 12))) - .reduce(|(a0, a1), (x0, x1)| (a0 + x0, a1 + x1)) - .unwrap(); - - println!("silver: {silver}"); - println!("gold: {gold}"); -} |
