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/10/python.py | 43 --------------------------------------- 2024/10/rust/Cargo.lock | 7 ------- 2024/10/rust/Cargo.toml | 6 ------ 2024/10/rust/src/main.rs | 52 ------------------------------------------------ 4 files changed, 108 deletions(-) delete mode 100755 2024/10/python.py delete mode 100644 2024/10/rust/Cargo.lock delete mode 100644 2024/10/rust/Cargo.toml delete mode 100644 2024/10/rust/src/main.rs (limited to '2024/10') diff --git a/2024/10/python.py b/2024/10/python.py deleted file mode 100755 index 88892b6..0000000 --- a/2024/10/python.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 - -from fileinput import input - -grid = [[int(c) for c in line.strip()] for line in input()] - -starts = { - (idx, idy) for idy, line in enumerate(grid) for idx, n in enumerate(line) if n == 0 -} - -# print(*grid, sep="\n") -# print(starts) - - -def score_trailhead(start, gold): - score = 0 - q = [start] - seen = set() - while q: - x, y = q.pop() - seen.add((x, y)) - - h = grid[y][x] - if h == 9: - score += 1 - continue - for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]: - nx, ny = x + dx, y + dy - if ((nx, ny) in seen and not gold) or not ( - 0 <= nx < len(grid) and 0 <= ny < len(grid[0]) - ): - continue - - if grid[ny][nx] == h + 1: - q.append((nx, ny)) - return score - - -silver = sum(score_trailhead(start, False) for start in starts) -gold = sum(score_trailhead(start, True) for start in starts) - -print("silver:", silver) -print("gold:", gold) diff --git a/2024/10/rust/Cargo.lock b/2024/10/rust/Cargo.lock deleted file mode 100644 index de24ddf..0000000 --- a/2024/10/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-10" -version = "0.1.0" diff --git a/2024/10/rust/Cargo.toml b/2024/10/rust/Cargo.toml deleted file mode 100644 index 787d795..0000000 --- a/2024/10/rust/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "aoc_2024-10" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/2024/10/rust/src/main.rs b/2024/10/rust/src/main.rs deleted file mode 100644 index b5b3825..0000000 --- a/2024/10/rust/src/main.rs +++ /dev/null @@ -1,52 +0,0 @@ -use std::collections::HashSet; -use std::io; - -fn main() -> io::Result<()> { - let grid: Vec> = io::stdin() - .lines() - .flatten() - .map(|s| s.chars().map(|c| c.to_digit(10).unwrap() as u8).collect()) - .collect(); - - let starts = grid - .iter() - .enumerate() - .flat_map(|(y, row)| row.iter().enumerate().map(move |(x, d)| (x, y, d))) - .filter_map(|(x, y, d)| (*d == 0).then_some((y, x))) - .collect::>(); - - let silver: usize = starts.iter().map(|&s| trailheads(s, &grid, false)).sum(); - let gold: usize = starts.iter().map(|&s| trailheads(s, &grid, true)).sum(); - - println!("silver: {silver}"); - println!("gold: {gold}"); - - return Ok(()); -} - -fn trailheads(start: (usize, usize), grid: &Vec>, count_paths: bool) -> usize { - let mut seen = HashSet::new(); - let mut tot = 0; - let mut q = vec![start]; - - while let Some(curr @ (y, x)) = q.pop() { - seen.insert(curr); - let h = grid[y][x]; - if h == 9 { - tot += 1; - continue; - } - - [ - ((y + 1).min(grid.len() - 1), x), - (y, (x + 1).min(grid[0].len() - 1)), - (y.saturating_sub(1), x), - (y, x.saturating_sub(1)), - ] - .iter() - .filter(|&&(ny, nx)| grid[ny][nx] == h + 1) - .filter(|next| count_paths || !seen.contains(next)) - .for_each(|&n| q.push(n)); - } - tot -} -- cgit v1.2.3