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:
Ursprung
2bbf7c86f6
Commit
ed43974f0f
7 geänderte Dateien mit 108 neuen und 16 gelöschten Zeilen
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
112
src/lib.rs
112
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<T>
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Kartesian<T>
|
||||
where
|
||||
T: Integer,
|
||||
{
|
||||
x: T,
|
||||
y: T,
|
||||
pub x: 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)]
|
||||
struct Euclidian<T>
|
||||
pub struct Euclidian<T>
|
||||
where
|
||||
T: Integer,
|
||||
{
|
||||
x: T,
|
||||
y: T,
|
||||
z: T,
|
||||
pub x: T,
|
||||
pub y: 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)]
|
||||
enum KartesianDirection {
|
||||
pub enum KartesianDirection {
|
||||
TopLeft,
|
||||
Top,
|
||||
TopRight,
|
||||
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren