summaryrefslogtreecommitdiff
path: root/2025/09
diff options
context:
space:
mode:
authormhsn <mail@mhsn.net>2026-03-18 21:48:13 +0000
committermhsn <mail@mhsn.net>2026-03-18 21:48:13 +0000
commit86bac31392a76da84817eec020d2b84d099b3cc1 (patch)
treee2ee52db59b86b914d5b4bcceb19c9b5d899fff4 /2025/09
parent62fe361fc42dea75deaf7ac31c0ba6ba80e26a9c (diff)
downloadpuzzles-master.tar.gz
puzzles-master.zip
add other challenges supportHEADmaster
Diffstat (limited to '2025/09')
-rwxr-xr-x2025/09/python.py13
-rw-r--r--2025/09/rust/Cargo.lock7
-rw-r--r--2025/09/rust/Cargo.toml6
-rw-r--r--2025/09/rust/src/main.rs113
4 files changed, 0 insertions, 139 deletions
diff --git a/2025/09/python.py b/2025/09/python.py
deleted file mode 100755
index 6c4df6c..0000000
--- a/2025/09/python.py
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env python3
-
-from fileinput import input
-
-pts = [[*map(int, line.split(","))] for line in input()]
-
-silver = max(
- (abs(x1 - x2) + 1) * (abs(y1 - y2) + 1) for (x1, y1) in pts for (x2, y2) in pts
-)
-gold = 0
-
-print("silver:", silver)
-print("gold:", gold)
diff --git a/2025/09/rust/Cargo.lock b/2025/09/rust/Cargo.lock
deleted file mode 100644
index 1a33f1f..0000000
--- a/2025/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_2025-09"
-version = "0.1.0"
diff --git a/2025/09/rust/Cargo.toml b/2025/09/rust/Cargo.toml
deleted file mode 100644
index a713c42..0000000
--- a/2025/09/rust/Cargo.toml
+++ /dev/null
@@ -1,6 +0,0 @@
-[package]
-name = "aoc_2025-09"
-version = "0.1.0"
-edition = "2024"
-
-[dependencies]
diff --git a/2025/09/rust/src/main.rs b/2025/09/rust/src/main.rs
deleted file mode 100644
index 32847e3..0000000
--- a/2025/09/rust/src/main.rs
+++ /dev/null
@@ -1,113 +0,0 @@
-use std::io;
-
-#[derive(Debug)]
-struct Floor {
- x_comp: Vec<usize>,
- y_comp: Vec<usize>,
-}
-
-impl Floor {
- fn new(pts: Vec<(usize, usize)>) -> (Self, Vec<(usize, usize)>) {
- let (mut xs, mut ys): (Vec<_>, Vec<_>) = pts.clone().into_iter().unzip();
- xs.sort_unstable();
- xs.dedup();
- ys.sort_unstable();
- ys.dedup();
-
- let pts = pts
- .into_iter()
- .map(|(x, y)| (xs.binary_search(&x).unwrap(), ys.binary_search(&y).unwrap()))
- .collect();
-
- (
- Self {
- x_comp: xs,
- y_comp: ys,
- },
- pts,
- )
- }
-
- fn uncomp(&self, (x, y): (usize, usize)) -> (usize, usize) {
- (self.x_comp[x], self.y_comp[y])
- }
-
- fn area(&self, (p1, p2): ((usize, usize), (usize, usize))) -> usize {
- let (x1, y1) = self.uncomp(p1);
- let (x2, y2) = self.uncomp(p2);
- (x1.abs_diff(x2) + 1) * (y1.abs_diff(y2) + 1)
- }
-}
-
-fn main() {
- let pts = io::stdin()
- .lines()
- .flatten()
- .map(|line| {
- let (x, y) = line.split_once(',').unwrap();
- (x.parse().unwrap(), y.parse().unwrap())
- })
- .collect::<Vec<(usize, usize)>>();
-
- let (floor, pts) = Floor::new(pts);
-
- let xmax = *pts.iter().map(|(x, _)| x).max().unwrap();
- let ymax = *pts.iter().map(|(_, y)| y).max().unwrap();
-
- // some padding so that flood fill works correctly
- let mut grid: Vec<Vec<Option<bool>>> = vec![vec![None; xmax + 3]; ymax + 3];
-
- // draw green/red tiles
- for pair in [vec![*pts.last().unwrap()], pts.clone()]
- .concat()
- .windows(2)
- {
- let (x1, y1) = pair[0];
- let (x2, y2) = pair[1];
- (x1.min(x2)..=x1.max(x2)).for_each(|x| {
- (y1.min(y2)..=(y1.max(y2))).for_each(|y| grid[y + 1][x + 1] = Some(true))
- });
- }
-
- // flood fill from top left
- let mut q = vec![(0, 0)];
- while let Some((x, y)) = q.pop() {
- grid[y][x] = Some(false);
- let ns = vec![
- (x.saturating_sub(1), y),
- ((x + 1).min(xmax + 2), y),
- (x, y.saturating_sub(1)),
- (x, (y + 1).min(ymax + 2)),
- ];
- q.extend(ns.into_iter().filter(|&(x, y)| grid[y][x].is_none()));
- }
-
- // replace inside cells with Some(true) and undo the padding
- let grid: Vec<Vec<bool>> = grid
- .into_iter()
- .skip(1)
- .map(|r| r.into_iter().skip(1).map(|c| c.unwrap_or(true)).collect())
- .collect();
-
- let mut rectangles = pts
- .iter()
- .enumerate()
- .flat_map(|(idx, p1)| pts.iter().take(idx).map(move |p2| (*p1, *p2)))
- .collect::<Vec<_>>();
- rectangles.sort_unstable_by_key(|&r| std::cmp::Reverse(floor.area(r)));
-
- let silver: usize = floor.area(*rectangles.first().unwrap());
- let gold: usize = floor.area(
- *rectangles
- .iter()
- .filter(|&&((x1, y1), (x2, y2))| {
- (x1.min(x2)..=x1.max(x2))
- .flat_map(|x| (y1.min(y2)..=y1.max(y2)).map(move |y| (x, y)))
- .all(|(x, y)| grid[y][x])
- })
- .next()
- .unwrap(),
- );
- println!("silver: {silver}");
- println!("gold: {gold}");
-}