extended the library

Add and Sub plus the  assign variant are now implemented;
advent_of_code_macros is now pub use.
Dieser Commit ist enthalten in:
Sebastian Tobie 2024-12-06 16:56:47 +01:00
Ursprung 2bbf7c86f6
Commit ed43974f0f
7 geänderte Dateien mit 108 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,6 @@
use advent_of_code::strings::{get_numbers, get_string_numbers}; use advent_of_code::strings::{get_numbers, get_string_numbers};
#[allow(unused_imports)] #[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!(DATAa 2023 01a);
include_data!(DATAb 2023 01b); include_data!(DATAb 2023 01b);

Datei anzeigen

@ -1,6 +1,6 @@
use advent_of_code::strings::parsenumber; use advent_of_code::strings::parsenumber;
#[allow(unused_imports)] #[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); include_example!(DATA 2023 02);

Datei anzeigen

@ -1,6 +1,6 @@
use advent_of_code::strings::{parsenumber, splitspace}; use advent_of_code::strings::{parsenumber, splitspace};
#[allow(unused_imports)] #[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); include_data!(DATA 2024 01);

Datei anzeigen

@ -2,7 +2,7 @@ use std::fmt::Display;
use advent_of_code::strings::{convert_to_array, parsenumber}; use advent_of_code::strings::{convert_to_array, parsenumber};
#[allow(unused_imports)] #[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); include_data!(DATA 2024 02);

Datei anzeigen

@ -1,6 +1,6 @@
use advent_of_code::strings::parsenumber; use advent_of_code::strings::parsenumber;
#[allow(unused_imports)] #[allow(unused_imports)]
use advent_of_code_macros::{include_data, include_example}; use advent_of_code::{include_data, include_example};
use regex::{Captures, Regex}; use regex::{Captures, Regex};
include_data!(DATA 2024 03); include_data!(DATA 2024 03);

Datei anzeigen

@ -2,7 +2,7 @@
use std::ops::RangeInclusive; use std::ops::RangeInclusive;
#[allow(unused_imports)] #[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); include_data!(DATA 2024 04);

Datei anzeigen

@ -1,6 +1,9 @@
use std::ops::{Add, AddAssign, Sub, SubAssign};
use num::*; use num::*;
pub mod strings; pub mod strings;
pub use advent_of_code_macros::*;
pub fn matrix(zero: bool, diag: bool, non_diag: bool) -> Vec<(i32, i32)> { pub fn matrix(zero: bool, diag: bool, non_diag: bool) -> Vec<(i32, i32)> {
const MIN: i32 = -1; const MIN: i32 = -1;
@ -24,28 +27,117 @@ pub fn matrix(zero: bool, diag: bool, non_diag: bool) -> Vec<(i32, i32)> {
d d
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
struct Kartesian<T> pub struct Kartesian<T>
where where
T: Integer, T: Integer,
{ {
x: T, pub x: T,
y: T, pub y: T,
} }
impl<T: Integer> Add for Kartesian<T> {
fn add(self, rhs: Self) -> Self::Output {
Kartesian {
x: self.x + rhs.x,
y: self.y + rhs.y,
}
}
type Output = Kartesian<T>;
}
impl<T: Integer + Euclidian> AddAssign for Kartesian<T> {
fn add_assign(&mut self, rhs: Self) {
self.x += rhs.x;
self.y += rhs.y;
}
}
impl<T: Integer> Sub for Kartesian<T> {
fn sub(self, rhs: Self) -> Self::Output {
Kartesian {
x: self.x - rhs.x,
y: self.y - rhs.y,
}
}
type Output = Kartesian<T>;
}
impl<T: Integer + Euclidian> SubAssign for Kartesian<T> {
fn sub_assign(&mut self, rhs: Self) {
self.x -= rhs.x;
self.y -= rhs.y;
}
}
impl<T: Integer> Kartesian<T> {
pub const fn new(x: T, y: T) -> Self {
Self { x: x, y: y }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Euclidian<T> pub struct Euclidian<T>
where where
T: Integer, T: Integer,
{ {
x: T, pub x: T,
y: T, pub y: T,
z: T, pub z: T,
} }
type Table = Vec<Vec<char>>; impl<T: Integer> Add for Euclidian<T> {
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<T>;
}
impl<T: Integer + Euclidian> AddAssign for Euclidian<T> {
fn add_assign(&mut self, rhs: Self) {
self.x += rhs.x;
self.y += rhs.y;
self.z += rhs.z;
}
}
impl<T: Integer> Sub for Euclidian<T> {
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<T>;
}
impl<T: Integer + Euclidian> SubAssign for Euclidian<T> {
fn sub_assign(&mut self, rhs: Self) {
self.x -= rhs.x;
self.y -= rhs.y;
self.z -= rhs.z;
}
}
impl<T: Integer> Euclidian<T> {
pub const fn new(x: T, y: T) -> Self {
Self { x: x, y: y, z: z }
}
}
pub type Table = Vec<Vec<char>>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
enum KartesianDirection { pub enum KartesianDirection {
TopLeft, TopLeft,
Top, Top,
TopRight, TopRight,