From 27483d052f05ebba2e377856e0c71d918990948c Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 9 Dec 2022 17:43:10 -0500 Subject: [PATCH] Start on day 9 --- day8/README.md | 2 +- day9/Cargo.lock | 7 + day9/Cargo.toml | 8 + day9/README.md | 249 +++++ day9/src/grid.rs | 92 ++ day9/src/input.txt | 2000 +++++++++++++++++++++++++++++++++++++++ day9/src/main.rs | 18 + day9/src/test-input.txt | 8 + 8 files changed, 2383 insertions(+), 1 deletion(-) create mode 100644 day9/Cargo.lock create mode 100644 day9/Cargo.toml create mode 100644 day9/README.md create mode 100644 day9/src/grid.rs create mode 100644 day9/src/input.txt create mode 100644 day9/src/main.rs create mode 100644 day9/src/test-input.txt diff --git a/day8/README.md b/day8/README.md index 7b70a63..f6ce289 100644 --- a/day8/README.md +++ b/day8/README.md @@ -70,4 +70,4 @@ However, you can do even better: consider the tree of height 5 in the middle of This tree's scenic score is 8 (2 * 2 * 1 * 2); this is the ideal spot for the tree house. -Consider each tree on your map. What is the highest scenic score possible for any tree? \ No newline at end of file +Consider each tree on your map. **What is the highest scenic score possible for any tree?** \ No newline at end of file diff --git a/day9/Cargo.lock b/day9/Cargo.lock new file mode 100644 index 0000000..f5578cf --- /dev/null +++ b/day9/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "day9" +version = "0.1.0" diff --git a/day9/Cargo.toml b/day9/Cargo.toml new file mode 100644 index 0000000..b5e5273 --- /dev/null +++ b/day9/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day9" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day9/README.md b/day9/README.md new file mode 100644 index 0000000..dcb0d66 --- /dev/null +++ b/day9/README.md @@ -0,0 +1,249 @@ +# Day 9: Rope Bridge + +## Part 1 + +This rope bridge creaks as you walk along it. You aren't sure how old it is, or whether it can even support your weight. + +It seems to support the Elves just fine, though. The bridge spans a gorge which was carved out by the massive river far below you. + +You step carefully; as you do, the ropes stretch and twist. You decide to distract yourself by modeling rope physics; maybe you can even figure out where not to step. + +Consider a rope with a knot at each end; these knots mark the head and the tail of the rope. If the head moves far enough away from the tail, the tail is pulled toward the head. + +Due to nebulous reasoning involving Planck lengths, you should be able to model the positions of the knots on a two-dimensional grid. Then, by following a hypothetical series of motions (your puzzle input) for the head, you can determine how the tail will move. + +Due to the aforementioned Planck lengths, the rope must be quite short; in fact, the head (H) and tail (T) must always be touching (diagonally adjacent and even overlapping both count as touching): + + .... + .TH. + .... + + .... + .H.. + ..T. + .... + + ... + .H. (H covers T) + ... + +If the head is ever two steps directly up, down, left, or right from the tail, the tail must also move one step in that direction so it remains close enough: + + ..... ..... ..... + .TH.. -> .T.H. -> ..TH. + ..... ..... ..... + + ... ... ... + .T. .T. ... + .H. -> ... -> .T. + ... .H. .H. + ... ... ... + +Otherwise, if the head and tail aren't touching and aren't in the same row or column, the tail always moves one step diagonally to keep up: + + ..... ..... ..... + ..... ..H.. ..H.. + ..H.. -> ..... -> ..T.. + .T... .T... ..... + ..... ..... ..... + + ..... ..... ..... + ..... ..... ..... + ..H.. -> ...H. -> ..TH. + .T... .T... ..... + ..... ..... ..... + +You just need to work out where the tail goes as the head follows a series of motions. Assume the head and the tail both start at the same position, overlapping. + +For example: + + R 4 + U 4 + L 3 + D 1 + R 4 + D 1 + L 5 + R 2 + +This series of motions moves the head right four steps, then up four steps, then left three steps, then down one step, and so on. After each step, you'll need to update the position of the tail if the step means the head is no longer adjacent to the tail. Visually, these motions occur as follows (s marks the starting position as a reference point): + + == Initial State == + + ...... + ...... + ...... + ...... + H..... (H covers T, s) + + == R 4 == + + ...... + ...... + ...... + ...... + TH.... (T covers s) + + ...... + ...... + ...... + ...... + sTH... + + ...... + ...... + ...... + ...... + s.TH.. + + ...... + ...... + ...... + ...... + s..TH. + + == U 4 == + + ...... + ...... + ...... + ....H. + s..T.. + + ...... + ...... + ....H. + ....T. + s..... + + ...... + ....H. + ....T. + ...... + s..... + + ....H. + ....T. + ...... + ...... + s..... + + == L 3 == + + ...H.. + ....T. + ...... + ...... + s..... + + ..HT.. + ...... + ...... + ...... + s..... + + .HT... + ...... + ...... + ...... + s..... + + == D 1 == + + ..T... + .H.... + ...... + ...... + s..... + + == R 4 == + + ..T... + ..H... + ...... + ...... + s..... + + ..T... + ...H.. + ...... + ...... + s..... + + ...... + ...TH. + ...... + ...... + s..... + + ...... + ....TH + ...... + ...... + s..... + + == D 1 == + + ...... + ....T. + .....H + ...... + s..... + + == L 5 == + + ...... + ....T. + ....H. + ...... + s..... + + ...... + ....T. + ...H.. + ...... + s..... + + ...... + ...... + ..HT.. + ...... + s..... + + ...... + ...... + .HT... + ...... + s..... + + ...... + ...... + HT.... + ...... + s..... + + == R 2 == + + ...... + ...... + .H.... (H covers T) + ...... + s..... + + ...... + ...... + .TH... + ...... + s..... + +After simulating the rope, you can count up all of the positions the tail visited at least once. In this diagram, s again marks the starting position (which the tail also visited) and # marks other positions the tail visited: + + ..##.. + ...##. + .####. + ....#. + s###.. + +So, there are 13 positions the tail visited at least once. + +Simulate your complete hypothetical series of motions. How many positions does the tail of the rope visit at least once? diff --git a/day9/src/grid.rs b/day9/src/grid.rs new file mode 100644 index 0000000..c71b60c --- /dev/null +++ b/day9/src/grid.rs @@ -0,0 +1,92 @@ +/// A virtual 2d grid in an ordinary vector. Taken from day 8's puzzle solving implementation +#[derive(Debug)] +pub struct Grid { + width: usize, + pub vec: Vec, +} + +impl Grid { + pub fn new(width: usize) -> Self { + Grid { + width, + vec: Vec::new(), + } + } + + // Convert x,y coordinate into linear array index + pub fn xy_idx(&self, x: usize, y: usize) -> usize { + (y * self.width) + x + } + + /// Convert linear array index to x,y coordinate + pub fn idx_xy(&self, idx: usize) -> (usize, usize) { + (idx % self.width, idx / self.width) + } + + pub fn get(&self, idx: usize) -> Option<&T> { + self.vec.get(idx) + } + + pub fn get_mut(&mut self, idx: usize) -> Option<&mut T> { + self.vec.get_mut(idx) + } + + pub fn row_first_idx(&self, row: usize) -> usize { + let idx = row * self.width; + + if idx < self.vec.len() { + idx + } else { + self.vec.len() + } + } + + pub fn row_last_idx(&self, row: usize) -> usize { + if (row + 1) > self.num_rows() { + return self.vec.len(); + } + + self.row_first_idx(row + 1) - 1 + } + + pub fn num_rows(&self) -> usize { + self.vec.len() / self.width + } + + pub fn num_cols(&self) -> usize { + self.width + } + + pub fn get_row(&mut self, row_num: usize) -> &mut [T] { + let start = self.row_first_idx(row_num); + let end = self.row_last_idx(row_num); + + &mut self.vec[start..=end] + } + + pub fn get_row_indexes(&self, row_num: usize) -> Vec { + let start = self.row_first_idx(row_num); + let end = self.row_last_idx(row_num); + + (start..=end).collect() + } + + pub fn get_column_indexes(&self, col_num: usize) -> Vec { + let mut indexes = Vec::new(); + + if col_num >= self.num_cols() { + panic!( + "Asked for column {}, there are {} columns", + col_num, + self.num_cols() + ); + } + + for r in 0..self.num_rows() { + let idx = self.width * r + col_num; + indexes.push(idx); + } + + indexes + } +} \ No newline at end of file diff --git a/day9/src/input.txt b/day9/src/input.txt new file mode 100644 index 0000000..757d633 --- /dev/null +++ b/day9/src/input.txt @@ -0,0 +1,2000 @@ +R 1 +D 1 +L 1 +D 1 +R 2 +L 1 +U 2 +D 1 +U 2 +L 1 +U 1 +L 2 +D 1 +U 2 +L 1 +R 1 +D 1 +L 2 +D 2 +L 2 +R 1 +L 2 +U 2 +R 2 +L 2 +U 2 +L 1 +D 1 +L 2 +U 1 +R 1 +D 2 +L 2 +U 1 +R 1 +D 1 +U 2 +L 1 +D 2 +U 1 +D 1 +R 2 +D 1 +L 2 +D 1 +L 1 +R 1 +D 2 +L 1 +R 2 +D 2 +U 2 +R 2 +D 2 +R 2 +L 2 +D 2 +L 2 +D 1 +U 2 +R 1 +D 2 +L 2 +R 2 +L 1 +D 1 +U 2 +D 1 +R 2 +U 2 +R 2 +D 1 +L 1 +U 2 +D 1 +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 13 +L 1 +U 7 +R 16 +L 16 +U 1 +L 18 +D 16 +L 8 +U 2 +D 1 +R 2 +D 10 +U 8 +D 2 +R 18 +U 14 +D 15 +R 15 +U 3 +D 1 +U 17 +L 17 +D 15 +L 14 +R 6 +L 18 +U 19 +L 6 +U 17 +L 1 +D 2 +U 17 +R 11 +L 3 +R 3 +L 12 +U 1 +L 9 +U 13 +D 15 +U 12 +R 1 +L 5 +D 17 +L 14 +D 13 +L 2 +D 10 +U 5 +R 13 +L 19 +D 1 +R 12 +U 17 +R 15 +D 19 +U 12 +D 16 +R 2 +U 3 +R 15 +L 13 +U 11 +D 19 +R 10 +D 19 +L 2 +U 12 +R 5 +L 13 +U 13 +R 1 +D 11 +R 17 +D 7 +U 4 +D 14 +L 13 +R 8 +L 8 +D 8 diff --git a/day9/src/main.rs b/day9/src/main.rs new file mode 100644 index 0000000..dd1fc26 --- /dev/null +++ b/day9/src/main.rs @@ -0,0 +1,18 @@ +mod grid; + +use grid::Grid; + +// ---------------------------------------------------------------------------- + +fn main() { + let file_str = include_str!("input.txt"); +} + +#[cfg(test)] +mod tests { + use super::*; + + fn get_data() -> &'static str { + include_str!("test-input.txt") + } +} \ No newline at end of file diff --git a/day9/src/test-input.txt b/day9/src/test-input.txt new file mode 100644 index 0000000..cbea2b3 --- /dev/null +++ b/day9/src/test-input.txt @@ -0,0 +1,8 @@ +R 4 +U 4 +L 3 +D 1 +R 4 +D 1 +L 5 +R 2 \ No newline at end of file