commit f1e0d8a4c29d7a2ddc2420947e2cdf1a29ea105b
parent 256912bd55a13d6b5b9496cf160ae8dd06eddef3
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date: Fri, 9 Dec 2022 19:42:33 -0500
Add 2022 day 09
Diffstat:
3 files changed, 2096 insertions(+), 0 deletions(-)
diff --git a/2022/day09/Cargo.toml b/2022/day09/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "day09"
+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/2022/day09/input.txt b/2022/day09/input.txt
@@ -0,0 +1,2000 @@
+U 1
+R 2
+D 1
+L 1
+U 2
+D 1
+U 2
+L 1
+D 1
+U 2
+R 1
+U 1
+D 1
+R 1
+L 2
+D 1
+U 1
+D 1
+U 2
+D 2
+R 2
+D 1
+R 2
+D 2
+R 1
+L 2
+U 2
+D 2
+R 2
+D 1
+R 1
+L 1
+D 2
+U 2
+L 2
+U 2
+R 1
+L 1
+D 1
+R 1
+D 2
+U 1
+L 2
+R 1
+U 1
+D 1
+U 1
+D 2
+R 1
+L 1
+U 1
+L 1
+R 2
+U 1
+R 2
+L 2
+U 1
+R 1
+L 2
+R 2
+L 2
+U 1
+D 1
+U 2
+R 1
+D 1
+L 2
+D 1
+L 1
+U 1
+R 2
+U 1
+D 1
+L 2
+R 2
+D 2
+R 2
+D 1
+L 2
+D 1
+R 2
+L 1
+D 2
+R 2
+D 1
+U 1
+L 1
+R 2
+L 2
+D 1
+R 1
+L 1
+U 1
+L 1
+R 1
+U 2
+R 1
+D 2
+R 1
+L 2
+R 1
+L 1
+D 2
+R 2
+L 1
+U 1
+D 1
+L 2
+D 1
+L 1
+R 1
+U 1
+R 3
+U 2
+L 2
+R 1
+L 1
+D 1
+R 1
+U 2
+D 3
+L 1
+R 1
+U 2
+R 1
+U 1
+R 3
+L 3
+U 2
+D 1
+L 1
+R 1
+U 3
+D 1
+L 3
+D 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+U 2
+R 7
+D 14
+L 10
+U 8
+D 10
+U 4
+R 3
+L 1
+D 5
+U 18
+L 1
+U 9
+D 4
+R 3
+D 11
+R 9
+U 18
+D 12
+R 13
+L 8
+D 6
+U 13
+R 6
+U 15
+R 14
+U 11
+R 11
+D 15
+L 7
+R 11
+D 16
+U 14
+R 15
+D 16
+R 3
+D 10
+R 6
+U 17
+L 9
+R 1
+D 12
+R 18
+U 11
+L 2
+R 5
+L 10
+U 13
+L 3
+D 15
+U 14
+D 13
+R 5
+U 15
+L 9
+U 6
+D 16
+L 1
+U 1
+D 12
+R 18
+L 13
+R 10
+U 14
+L 13
+U 3
+L 2
+R 11
+U 18
+D 14
+R 4
+L 6
+R 10
+U 18
+L 18
+R 9
+L 11
+U 4
+D 5
+L 15
+R 13
+L 18
+U 16
+L 1
+R 12
+U 17
+D 11
+U 1
+L 13
+U 7
+D 3
+U 5
+R 8
+D 4
+L 7
+D 17
+U 9
+R 1
+L 18
+U 13
+L 7
+U 12
+D 2
+R 18
+D 12
+U 11
+R 13
+U 12
+L 13
+R 7
+U 6
+D 5
+L 13
+D 15
+R 12
+D 8
+L 19
+U 10
+L 4
+D 18
+U 9
+D 5
+U 2
+L 1
+D 2
+R 8
+U 9
+R 1
+D 11
+U 18
+R 11
+D 19
+U 6
+D 14
+U 6
+D 4
+U 2
+L 12
+D 15
+L 10
+R 5
+U 16
+L 3
+D 8
+L 10
+D 7
+R 16
+D 8
+R 6
+L 16
+R 6
+D 8
+U 15
+D 1
+L 14
+U 14
+R 16
+L 14
+D 2
+R 6
+D 5
+R 14
+L 15
+D 2
+R 15
+L 4
+U 18
+R 8
+D 6
+R 7
+L 2
+U 5
+L 19
+R 17
+L 19
+R 13
+L 2
+U 7
+D 19
+R 9
+L 8
+D 18
+U 2
+R 3
+U 7
+D 9
+R 12
+U 13
+L 15
+U 2
+D 6
+R 18
+D 7
+L 10
+R 4
+L 12
+D 6
+L 4
+D 10
+L 7
+U 12
+L 9
+R 12
+L 13
+R 13
+L 18
+R 18
+U 7
+D 5
+R 8
+D 18
+L 11
+D 5
+L 1
+U 6
+R 19
+U 17
+R 16
+L 8
+R 11
+U 17
+D 1
+R 11
+L 12
+D 4
+U 13
diff --git a/2022/day09/src/main.rs b/2022/day09/src/main.rs
@@ -0,0 +1,88 @@
+use std::cmp::Ordering;
+use std::collections::HashSet;
+
+#[derive(Debug)]
+enum Dir {
+ Left,
+ Right,
+ Up,
+ Down,
+}
+
+impl Dir {
+ fn from_str(s: &str) -> Self {
+ match s {
+ "L" => Self::Left,
+ "R" => Self::Right,
+ "U" => Self::Up,
+ "D" => Self::Down,
+ _ => unreachable!(),
+ }
+ }
+}
+
+fn sign(x: i32) -> i32 {
+ match x.cmp(&0) {
+ Ordering::Greater => 1,
+ Ordering::Equal => 0,
+ Ordering::Less => -1,
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+struct Coord(i32, i32);
+
+impl Coord {
+ fn move_in(&mut self, dir: &Dir) {
+ match dir {
+ Dir::Left => self.0 = self.0 - 1,
+ Dir::Right => self.0 = self.0 + 1,
+ Dir::Up => self.1 = self.1 + 1,
+ Dir::Down => self.1 = self.1 - 1,
+ }
+ }
+
+ fn is_touching(&self, other: &Coord) -> bool {
+ return (other.0 - self.0).abs() <= 1 && (other.1 - self.1).abs() <= 1;
+ }
+
+ fn follow(&mut self, other: &Coord) {
+ self.0 = self.0 + sign(other.0 - self.0);
+ self.1 = self.1 + sign(other.1 - self.1);
+ }
+}
+
+fn main() {
+ let input = std::fs::read_to_string("input.txt")
+ .unwrap()
+ .trim()
+ .split("\n")
+ .map(|x| {
+ let tmp = x.split(' ').collect::<Vec<_>>();
+ (Dir::from_str(tmp[0]), tmp[1].parse::<i32>().unwrap())
+ })
+ .collect::<Vec<(Dir, i32)>>();
+ // 6087
+ println!("Part 1: {}", part_1(&input, 2));
+ // 2493
+ println!("Part 2: {}", part_1(&input, 10));
+}
+
+fn part_1(input: &Vec<(Dir, i32)>, rope_length: usize) -> usize {
+ let mut rope = vec![Coord(0, 0); rope_length];
+ let mut visited = HashSet::new();
+ visited.insert(rope.last().unwrap().clone());
+ for (dir, step) in input {
+ for _ in 0..*step {
+ rope[0].move_in(dir);
+ for i in 1..rope_length {
+ if !rope[i].is_touching(&rope[i - 1]) {
+ let tmp = rope[i - 1].clone();
+ rope[i].follow(&tmp);
+ }
+ }
+ visited.insert(rope.last().unwrap().clone());
+ }
+ }
+ visited.len()
+}