summaryrefslogtreecommitdiff
path: root/2024/04
diff options
context:
space:
mode:
Diffstat (limited to '2024/04')
-rwxr-xr-x2024/04/python.py29
-rwxr-xr-x2024/04/raku.raku8
-rw-r--r--2024/04/rust/Cargo.lock7
-rw-r--r--2024/04/rust/Cargo.toml4
-rw-r--r--2024/04/rust/src/main.rs82
5 files changed, 0 insertions, 130 deletions
diff --git a/2024/04/python.py b/2024/04/python.py
deleted file mode 100755
index fe5021b..0000000
--- a/2024/04/python.py
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env python3
-
-from fileinput import input
-
-grid = {
- complex(idx, idy): c
- for idy, line in enumerate(input())
- for idx, c in enumerate(line.strip())
-}
-dirs = {complex(dx, dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1]}
-
-
-def xmas(x, v):
- return all(grid.get(x + n * v) == c for n, c in enumerate("XMAS"))
-
-
-def x_mas(x, v):
- return (
- grid.get(x) == "A"
- and grid.get(x + v) == grid.get(x + 1j * v) == "M"
- and grid.get(x - v) == grid.get(x - 1j * v) == "S"
- )
-
-
-silver = sum(xmas(x, v) for x in grid.keys() for v in dirs)
-gold = sum(x_mas(x, v) for x in grid.keys() for v in dirs if abs(v) > 1)
-
-print("silver:", silver)
-print("gold:", gold)
diff --git a/2024/04/raku.raku b/2024/04/raku.raku
deleted file mode 100755
index 6055fe4..0000000
--- a/2024/04/raku.raku
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env raku
-
-my @g = lines.map: *.comb.Array;
-
-@g.map: *.say;
-say "---";
-
-say @g[.[0]; .[1] .. .[1]+3] for (^@g X ^@g[0])[^4];
diff --git a/2024/04/rust/Cargo.lock b/2024/04/rust/Cargo.lock
deleted file mode 100644
index 832036f..0000000
--- a/2024/04/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-04"
-version = "0.1.0"
diff --git a/2024/04/rust/Cargo.toml b/2024/04/rust/Cargo.toml
deleted file mode 100644
index e872faf..0000000
--- a/2024/04/rust/Cargo.toml
+++ /dev/null
@@ -1,4 +0,0 @@
-[package]
-name = "aoc_2024-04"
-version = "0.1.0"
-edition = "2021"
diff --git a/2024/04/rust/src/main.rs b/2024/04/rust/src/main.rs
deleted file mode 100644
index 191e461..0000000
--- a/2024/04/rust/src/main.rs
+++ /dev/null
@@ -1,82 +0,0 @@
-use std::io;
-
-fn main() -> io::Result<()> {
- let grid = io::stdin()
- .lines()
- .flatten()
- .map(|line| line.chars().collect())
- .collect::<Vec<Vec<char>>>();
- let grid = Grid(grid);
-
- let silver: usize = silver(&grid);
- let gold: usize = gold(&grid);
-
- println!("silver: {silver}");
- println!("gold: {gold}");
-
- return Ok(());
-}
-
-struct Grid(Vec<Vec<char>>);
-
-impl Grid {
- fn at(&self, (x, y): (isize, isize)) -> Option<&char> {
- self.0
- .get(usize::try_from(y).ok()?)?
- .get(usize::try_from(x).ok()?)
- }
-
- fn check<'a>(
- &self,
- (x, y): (isize, isize),
- mut pat: impl Iterator<Item = &'a ((isize, isize), char)>,
- ) -> bool {
- pat.all(|((dx, dy), ch)| self.at((x + dx, y + dy)).is_some_and(|c| c == ch))
- }
-
- fn pts(&self) -> impl Iterator<Item = (isize, isize)> + use<'_> {
- (0..self.0[0].len()).flat_map(|x| (0..self.0.len()).map(move |y| (x as isize, y as isize)))
- }
-}
-
-fn silver(grid: &Grid) -> usize {
- let dirs = vec![
- (-1, -1),
- (-1, 0),
- (-1, 1),
- (0, -1),
- (0, 1),
- (1, -1),
- (1, 0),
- (1, 1),
- ];
-
- let xmases: Vec<Vec<((isize, isize), char)>> = dirs
- .iter()
- .map(|(dx, dy)| {
- (0..4)
- .map(move |n| (dx * n, dy * n))
- .zip("XMAS".chars())
- .collect()
- })
- .collect();
-
- grid.pts()
- .flat_map(|p| xmases.iter().map(move |xmas| grid.check(p, xmas.iter())))
- .filter(|p| *p)
- .count()
-}
-
-fn gold(grid: &Grid) -> usize {
- let dirs = vec![(-1, -1), (1, -1), (0, 0), (-1, 1), (1, 1)];
-
- let xmases: Vec<Vec<((isize, isize), char)>> = vec!["MMASS", "SMASM", "SSAMM", "MSAMS"]
- .iter()
- .map(|x| dirs.clone().into_iter().zip(x.chars()).collect())
- .collect();
-
- grid.pts()
- .flat_map(|p| xmases.iter().map(move |xmas| grid.check(p, xmas.iter())))
- .filter(|p| *p)
- .count()
-}