diff --git a/aoc-shared/src/grid.rs b/aoc-shared/src/grid.rs index f1c6763..e224422 100644 --- a/aoc-shared/src/grid.rs +++ b/aoc-shared/src/grid.rs @@ -18,6 +18,10 @@ impl Grid { self.vec.len() } + pub fn is_empty(&self) -> bool { + self.vec.is_empty() + } + pub fn num_cols(&self) -> usize { self.width } diff --git a/aoc-shared/src/lib.rs b/aoc-shared/src/lib.rs index 4657362..f7d9ad1 100644 --- a/aoc-shared/src/lib.rs +++ b/aoc-shared/src/lib.rs @@ -2,6 +2,25 @@ pub mod grid; pub mod enums; pub use grid::*; +pub use enums::*; + +#[derive(Debug, Default, Copy, Clone, Eq, Hash, PartialEq)] +pub struct Location { + pub x: isize, + pub y: isize, +} + +impl Location { + pub fn new(x: isize, y: isize) -> Self { + Location { x, y } + } + + pub fn get_distance(self, other: Self) -> f64 { + let squares = (other.x - self.x).pow(2) + (other.y - self.y).pow(2); + + (squares as f64).sqrt() + } +} #[macro_export] macro_rules! deref { diff --git a/day9/src/main.rs b/day9/src/main.rs index 3872c67..e40fa7e 100644 --- a/day9/src/main.rs +++ b/day9/src/main.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; -use aoc_shared::enums::*; -use aoc_shared::enums::Direction::*; +use aoc_shared::{Location, Direction}; +use aoc_shared::Direction::*; struct Move { dir: Direction, @@ -24,24 +24,6 @@ impl Move { } } -#[derive(Debug, Default, Copy, Clone, Eq, Hash, PartialEq)] -struct Location { - x: isize, - y: isize, -} - -impl Location { - fn new(x: isize, y: isize) -> Self { - Location { x, y } - } - - fn get_distance(self, other: Self) -> f64 { - let squares = (other.x - self.x).pow(2) + (other.y - self.y).pow(2); - - (squares as f64).sqrt() - } -} - // --------------------------------------------------------------------------- #[derive(Debug, Default)] @@ -97,8 +79,6 @@ impl Rope { for i in 1..self.knot_count { self.move_knot(i, i - 1); } - // self.head = to; - // self.head_visited.insert(to); } }