From dd201caa137401da6f0bd386d710bf836b53564b Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Fri, 9 Dec 2022 12:16:58 +0000 Subject: day9 --- input/day9.txt | 2000 ++++++++++++++++++++++++++++++++++++++++++++++++++++ input/day9_ex.txt | 8 + input/day9_ex2.txt | 8 + src/day9.rs | 56 ++ src/main.rs | 2 + 5 files changed, 2074 insertions(+) create mode 100644 input/day9.txt create mode 100644 input/day9_ex.txt create mode 100644 input/day9_ex2.txt create mode 100644 src/day9.rs diff --git a/input/day9.txt b/input/day9.txt new file mode 100644 index 0000000..e043f8c --- /dev/null +++ b/input/day9.txt @@ -0,0 +1,2000 @@ +U 1 +L 2 +U 2 +D 2 +L 2 +U 1 +D 1 +U 2 +D 1 +U 2 +D 1 +R 2 +U 2 +L 1 +U 2 +D 2 +R 1 +U 1 +R 2 +L 1 +R 2 +D 2 +R 2 +D 2 +U 1 +R 1 +D 2 +L 2 +D 1 +R 2 +D 2 +R 1 +L 2 +R 1 +L 2 +R 1 +U 1 +D 2 +L 1 +D 1 +R 1 +U 1 +D 2 +L 1 +U 1 +L 2 +R 1 +D 2 +U 1 +L 1 +D 1 +L 1 +R 2 +D 1 +L 1 +R 1 +L 2 +D 2 +U 2 +D 1 +R 2 +U 1 +L 1 +U 2 +L 1 +U 2 +R 2 +U 1 +D 1 +L 2 +R 2 +D 2 +L 1 +D 2 +R 2 +D 1 +L 1 +D 2 +L 1 +R 1 +L 1 +R 2 +U 1 +R 1 +D 1 +R 1 +D 2 +R 2 +D 2 +U 1 +L 1 +D 1 +R 1 +L 2 +D 1 +U 2 +D 1 +R 1 +D 2 +U 2 +D 1 +R 1 +D 1 +R 1 +U 2 +L 1 +U 1 +R 1 +L 2 +R 1 +L 1 +D 2 +L 2 +R 1 +D 3 +L 3 +U 1 +R 2 +U 1 +R 2 +L 1 +D 1 +L 3 +U 2 +L 3 +D 1 +U 2 +L 3 +U 1 +R 2 +L 1 +R 1 +L 2 +D 2 +R 3 +L 1 +U 1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U 12 +R 10 +D 12 +R 15 +L 15 +U 11 +L 14 +D 15 +U 12 +D 7 +U 15 +L 1 +U 2 +R 18 +L 15 +U 7 +L 8 +R 3 +D 14 +R 7 +D 7 +U 6 +R 10 +L 9 +R 9 +D 17 +R 11 +D 4 +L 16 +U 12 +R 10 +L 4 +D 7 +U 18 +L 11 +U 3 +L 13 +U 5 +R 11 +D 16 +U 14 +D 1 +R 18 +D 4 +L 7 +U 2 +D 9 +L 5 +R 14 +U 18 +R 2 +U 7 +R 8 +U 9 +L 6 +R 12 +U 15 +R 1 +L 7 +D 3 +U 10 +R 5 +U 2 +L 8 +R 13 +L 14 +D 10 +L 10 +U 12 +R 5 +L 13 +D 8 +U 5 +D 17 +L 8 +D 8 +L 7 +U 5 +D 16 +R 9 +D 6 +U 11 +D 16 +U 15 +D 6 +L 4 +R 16 +D 8 +L 11 +U 13 +R 14 +L 12 +D 2 +U 16 +D 1 +L 12 +D 10 +R 1 +D 17 +L 8 +U 13 +R 10 +U 9 +D 4 +R 1 +U 17 +L 5 +D 15 +U 9 +R 15 +U 18 +L 15 +D 18 +U 15 +D 1 +L 9 +R 6 +L 15 +R 3 +D 19 +L 5 +D 10 +L 18 +D 11 +L 14 +D 11 +U 19 +D 5 +R 9 +L 18 +R 11 +D 3 +L 7 +R 4 +D 13 +L 9 +R 14 +D 14 +L 8 +U 10 +L 11 +U 4 +D 13 +R 13 +L 7 +R 7 +D 18 +U 2 +L 17 +D 16 +R 3 +U 12 +L 13 +U 5 +L 1 +U 9 +R 6 +D 14 +U 6 +R 3 +U 6 +R 7 +D 8 +U 11 +L 11 +R 7 +U 17 +D 2 +L 12 +U 18 +L 3 +U 14 +L 6 +R 10 +L 16 +U 19 +D 9 +R 13 +U 5 +R 5 +D 15 +R 1 +L 1 +U 5 +D 16 +L 5 +R 15 +L 14 +D 5 +R 9 +U 12 +L 9 +U 7 +R 16 +D 16 +R 10 +D 15 +R 16 +L 2 +U 13 +L 5 +D 19 +R 18 +D 19 +R 16 +D 12 +R 15 +D 12 +U 5 +L 3 +R 14 +D 7 +U 11 +R 10 +L 18 +D 9 +U 2 +D 19 +U 8 +D 19 +U 18 +R 11 +D 2 +R 8 +D 14 \ No newline at end of file diff --git a/input/day9_ex.txt b/input/day9_ex.txt new file mode 100644 index 0000000..cbea2b3 --- /dev/null +++ b/input/day9_ex.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 diff --git a/input/day9_ex2.txt b/input/day9_ex2.txt new file mode 100644 index 0000000..c1eba0a --- /dev/null +++ b/input/day9_ex2.txt @@ -0,0 +1,8 @@ +R 5 +U 8 +L 8 +D 3 +R 17 +D 10 +L 25 +U 20 \ No newline at end of file diff --git a/src/day9.rs b/src/day9.rs new file mode 100644 index 0000000..ac21e4d --- /dev/null +++ b/src/day9.rs @@ -0,0 +1,56 @@ +use core::panic; +use std::collections::HashSet; + +type Pt = (i32, i32); +/** + * how should the tail move to catch up with the head? + */ +fn catchup(head: Pt, tail: Pt) -> Pt { + let (hx, hy) = head; + let (tx, ty) = tail; + let xdiff = hx - tx; + let ydiff = hy - ty; + // only move if we're not adjescent (incl diagonally) + if xdiff.abs() > 1 || ydiff.abs() > 1 { + // only move 1 square (x and or y) in the direction of the head + (tail.0 + xdiff.signum(), tail.1 + ydiff.signum()) + } else { + (tail.0, tail.1) + } + +} +pub fn run(input: String) { + // series of steps + // let mut head: Pt = (0,0); + // let mut tail: Pt = (0,0); + // let mut htrail: Vec = Vec::new(); + let mut rope: Vec = (0..10).map(|_| { (0,0) as Pt}).collect(); + let mut trail: Vec = Vec::new(); + for line in input.lines() { + let mut toks = line.split_whitespace(); + let dir: &str = toks.next().expect("expected a direction!"); + let reps: u32 = toks.next().expect("expected a reps!").parse().expect("reps wasn't a number!"); + for _ in 0..reps { + let head = rope[0]; + let newhead = match dir { + "U" => (head.0, head.1+1), + "D" => (head.0, head.1-1), + "L" => (head.0-1, head.1), + "R" => (head.0+1, head.1), + dir => panic!("unexpected direction {}", dir), + }; + rope[0] = newhead; + for l in 1..rope.len() { + rope[l] = catchup(rope[l-1], rope[l]); + } + let tail = rope.last().unwrap(); + // htrail.push(head); + // tail = catchup(head, tail); + trail.push(*tail); + } + } + //println!("htrail {:?}", htrail); + //println!("trail {:?}", trail); + let trailsz = trail.into_iter().collect::>().len(); + println!("Day 9: {}", trailsz); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5a7634b..e9ea587 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ mod day5; mod day6; mod day7; mod day8; +mod day9; fn main() { day1::run(fs::read_to_string("input/day1.txt").expect("Failed to read input file!")); @@ -18,4 +19,5 @@ fn main() { day6::run(fs::read_to_string("input/day6.txt").expect("Failed to read input file!")); day7::run(fs::read_to_string("input/day7.txt").expect("Failed to read input file!")); day8::run(fs::read_to_string("input/day8.txt").expect("Failed to read input file!")); + day9::run(fs::read_to_string("input/day9.txt").expect("Failed to read input file!")); } -- cgit v1.2.3-ZIG