diff --git a/src/bin/2023/01.rs b/src/bin/2023/01.rs index 0b6b46f..750436d 100644 --- a/src/bin/2023/01.rs +++ b/src/bin/2023/01.rs @@ -1,6 +1,6 @@ use advent_of_code::strings::{get_numbers, get_string_numbers}; #[allow(unused_imports)] -use advent_of_code_macros::{include_data, include_example}; +use advent_of_code::{include_data, include_example}; include_data!(DATAa 2023 01a); include_data!(DATAb 2023 01b); diff --git a/src/bin/2023/02.rs b/src/bin/2023/02.rs index 0f7d110..19cf441 100644 --- a/src/bin/2023/02.rs +++ b/src/bin/2023/02.rs @@ -1,6 +1,6 @@ use advent_of_code::strings::parsenumber; #[allow(unused_imports)] -use advent_of_code_macros::{include_data, include_example}; +use advent_of_code::{include_data, include_example}; include_example!(DATA 2023 02); diff --git a/src/bin/2024/01.rs b/src/bin/2024/01.rs index 2cd5eb9..4b28e82 100644 --- a/src/bin/2024/01.rs +++ b/src/bin/2024/01.rs @@ -1,6 +1,6 @@ use advent_of_code::strings::{parsenumber, splitspace}; #[allow(unused_imports)] -use advent_of_code_macros::{include_data, include_example}; +use advent_of_code::{include_data, include_example}; include_data!(DATA 2024 01); diff --git a/src/bin/2024/02.rs b/src/bin/2024/02.rs index 7b9b65b..a52da09 100644 --- a/src/bin/2024/02.rs +++ b/src/bin/2024/02.rs @@ -2,7 +2,7 @@ use std::fmt::Display; use advent_of_code::strings::{convert_to_array, parsenumber}; #[allow(unused_imports)] -use advent_of_code_macros::{include_data, include_example}; +use advent_of_code::{include_data, include_example}; include_data!(DATA 2024 02); diff --git a/src/bin/2024/03.rs b/src/bin/2024/03.rs index bcbcf81..fa98d31 100644 --- a/src/bin/2024/03.rs +++ b/src/bin/2024/03.rs @@ -1,6 +1,6 @@ use advent_of_code::strings::parsenumber; #[allow(unused_imports)] -use advent_of_code_macros::{include_data, include_example}; +use advent_of_code::{include_data, include_example}; use regex::{Captures, Regex}; include_data!(DATA 2024 03); diff --git a/src/bin/2024/04.rs b/src/bin/2024/04.rs index 1218eea..814feeb 100644 --- a/src/bin/2024/04.rs +++ b/src/bin/2024/04.rs @@ -2,7 +2,7 @@ use std::ops::RangeInclusive; #[allow(unused_imports)] -use advent_of_code_macros::{include_data, include_example}; +use advent_of_code::{include_data, include_example}; include_data!(DATA 2024 04); diff --git a/src/lib.rs b/src/lib.rs index 08b3b9a..e961e27 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,9 @@ +use std::ops::{Add, AddAssign, Sub, SubAssign}; + use num::*; pub mod strings; +pub use advent_of_code_macros::*; pub fn matrix(zero: bool, diag: bool, non_diag: bool) -> Vec<(i32, i32)> { const MIN: i32 = -1; @@ -24,28 +27,117 @@ pub fn matrix(zero: bool, diag: bool, non_diag: bool) -> Vec<(i32, i32)> { d } -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -struct Kartesian +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)] +pub struct Kartesian where T: Integer, { - x: T, - y: T, + pub x: T, + pub y: T, } + +impl Add for Kartesian { + fn add(self, rhs: Self) -> Self::Output { + Kartesian { + x: self.x + rhs.x, + y: self.y + rhs.y, + } + } + + type Output = Kartesian; +} + +impl AddAssign for Kartesian { + fn add_assign(&mut self, rhs: Self) { + self.x += rhs.x; + self.y += rhs.y; + } +} + +impl Sub for Kartesian { + fn sub(self, rhs: Self) -> Self::Output { + Kartesian { + x: self.x - rhs.x, + y: self.y - rhs.y, + } + } + + type Output = Kartesian; +} + +impl SubAssign for Kartesian { + fn sub_assign(&mut self, rhs: Self) { + self.x -= rhs.x; + self.y -= rhs.y; + } +} + +impl Kartesian { + pub const fn new(x: T, y: T) -> Self { + Self { x: x, y: y } + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -struct Euclidian +pub struct Euclidian where T: Integer, { - x: T, - y: T, - z: T, + pub x: T, + pub y: T, + pub z: T, } -type Table = Vec>; +impl Add for Euclidian { + fn add(self, rhs: Self) -> Self::Output { + Euclidian { + x: self.x + rhs.x, + y: self.y + rhs.y, + z: self.z + rhs.z, + } + } + + type Output = Euclidian; +} + +impl AddAssign for Euclidian { + fn add_assign(&mut self, rhs: Self) { + self.x += rhs.x; + self.y += rhs.y; + self.z += rhs.z; + } +} + +impl Sub for Euclidian { + fn sub(self, rhs: Self) -> Self::Output { + Euclidian { + x: self.x - rhs.x, + y: self.y - rhs.y, + z: self.z - rhs.z, + } + } + + type Output = Euclidian; +} + +impl SubAssign for Euclidian { + fn sub_assign(&mut self, rhs: Self) { + self.x -= rhs.x; + self.y -= rhs.y; + self.z -= rhs.z; + } +} + +impl Euclidian { + pub const fn new(x: T, y: T) -> Self { + Self { x: x, y: y, z: z } + } +} + +pub type Table = Vec>; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -enum KartesianDirection { +pub enum KartesianDirection { TopLeft, Top, TopRight,