summaryrefslogtreecommitdiff
path: root/2024/06
diff options
context:
space:
mode:
authormhsn <mail@mhsn.net>2025-08-07 21:35:55 +0100
committermhsn <mail@mhsn.net>2025-08-07 21:35:55 +0100
commit10bb2a67c5bb005b304508eb2026780531132f82 (patch)
tree4e4f72ea6a1fee203fa6c34ed6cc5b570d507100 /2024/06
parent81232bba7f13c0cb2929f8ab44b789020ccb978f (diff)
downloadaoc-10bb2a67c5bb005b304508eb2026780531132f82.tar.gz
aoc-10bb2a67c5bb005b304508eb2026780531132f82.zip
2024-06 rust p1
Diffstat (limited to '2024/06')
-rw-r--r--2024/06/rust/Cargo.lock14
-rw-r--r--2024/06/rust/Cargo.toml7
-rw-r--r--2024/06/rust/src/main.rs43
3 files changed, 64 insertions, 0 deletions
diff --git a/2024/06/rust/Cargo.lock b/2024/06/rust/Cargo.lock
new file mode 100644
index 0000000..a049cf0
--- /dev/null
+++ b/2024/06/rust/Cargo.lock
@@ -0,0 +1,14 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "aoc"
+version = "0.1.0"
+
+[[package]]
+name = "aoc_2024-06"
+version = "0.1.0"
+dependencies = [
+ "aoc",
+]
diff --git a/2024/06/rust/Cargo.toml b/2024/06/rust/Cargo.toml
new file mode 100644
index 0000000..f478719
--- /dev/null
+++ b/2024/06/rust/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "aoc_2024-06"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+aoc = { version = "0.1.0", path = "../../../lib/rust" }
diff --git a/2024/06/rust/src/main.rs b/2024/06/rust/src/main.rs
new file mode 100644
index 0000000..92ac02d
--- /dev/null
+++ b/2024/06/rust/src/main.rs
@@ -0,0 +1,43 @@
+use std::io;
+
+use aoc::grid::{Direction, Grid};
+use std::collections::HashSet;
+
+fn main() -> io::Result<()> {
+ let grid: Vec<Vec<char>> = io::stdin()
+ .lines()
+ .map(|line| line.unwrap().chars().collect())
+ .collect();
+ let grid = Grid::new(grid);
+ let start = grid
+ .enumerate()
+ .filter(|(_, c)| **c == '^')
+ .next()
+ .unwrap()
+ .0;
+
+ let silver: usize = silver(&grid, start);
+ let gold: usize = gold(&grid);
+ println!("silver: {silver}");
+ println!("gold: {gold}");
+
+ return Ok(());
+}
+
+fn silver(grid: &Grid<char>, start: (usize, usize)) -> usize {
+ let mut pos = start;
+ let mut dir = Direction { x: 0, y: -1 };
+ let mut seen = HashSet::<(usize, usize)>::new();
+ loop {
+ seen.insert(pos);
+ match grid.move_pos(pos, dir, 1).and_then(|p| grid.at(p)) {
+ Some(&'#') => dir = dir.cw(),
+ Some(_) => pos = grid.move_pos(pos, dir, 1).unwrap(),
+ None => break seen.len(),
+ }
+ }
+}
+
+fn gold(grid: &Grid<char>) -> usize {
+ 0
+}