updated my library
Dieser Commit ist enthalten in:
Ursprung
4f32ca95cf
Commit
855772e976
5 geänderte Dateien mit 169 neuen und 2 gelöschten Zeilen
80
Cargo.lock
generiert
80
Cargo.lock
generiert
|
@ -7,6 +7,7 @@ name = "advent-of-code"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"advent-of-code-macros",
|
"advent-of-code-macros",
|
||||||
|
"num",
|
||||||
"regex",
|
"regex",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -28,12 +29,91 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.7.4"
|
version = "2.7.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
|
||||||
|
dependencies = [
|
||||||
|
"num-bigint",
|
||||||
|
"num-complex",
|
||||||
|
"num-integer",
|
||||||
|
"num-iter",
|
||||||
|
"num-rational",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-bigint"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
|
||||||
|
dependencies = [
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-complex"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.46"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-iter"
|
||||||
|
version = "0.1.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-rational"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
|
||||||
|
dependencies = [
|
||||||
|
"num-bigint",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.92"
|
version = "1.0.92"
|
||||||
|
|
|
@ -309,6 +309,7 @@ path = "src/bin/2024/25.rs"
|
||||||
name = "advent_of_code"
|
name = "advent_of_code"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
num="0.4.*"
|
||||||
|
|
||||||
[dependencies.advent-of-code-macros]
|
[dependencies.advent-of-code-macros]
|
||||||
path = "macros"
|
path = "macros"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use advent_of_code::strings::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_macros::{include_data, include_example};
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ fn safe(record: Vec<u32>) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let numbers = DATA.split('\n').map(get_numbers);
|
let numbers = convert_to_array(DATA, get_numbers);
|
||||||
let mut safe_reports = 0;
|
let mut safe_reports = 0;
|
||||||
let mut safe_with_dampener = 0;
|
let mut safe_with_dampener = 0;
|
||||||
for report in numbers {
|
for report in numbers {
|
||||||
|
|
77
src/lib.rs
77
src/lib.rs
|
@ -1 +1,78 @@
|
||||||
|
use num::*;
|
||||||
|
|
||||||
pub mod strings;
|
pub mod strings;
|
||||||
|
|
||||||
|
pub fn matrix(zero: bool, diag: bool, non_diag: bool) -> Vec<(i32, i32)> {
|
||||||
|
const MIN: i32 = -1;
|
||||||
|
const MAX: i32 = 1;
|
||||||
|
let mut d = Vec::new();
|
||||||
|
for i in MIN..=MAX {
|
||||||
|
for j in MIN..=MAX {
|
||||||
|
let ia = i.abs();
|
||||||
|
let ja = j.abs();
|
||||||
|
if zero && i == 0 && j == 0 {
|
||||||
|
d.push((i, j));
|
||||||
|
}
|
||||||
|
if diag && ia == 1 && ja == 1 {
|
||||||
|
d.push((i, j));
|
||||||
|
}
|
||||||
|
if non_diag && ia != ja && ia + ja == 1 {
|
||||||
|
d.push((i, j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
struct Kartesian<T>
|
||||||
|
where
|
||||||
|
T: Integer,
|
||||||
|
{
|
||||||
|
x: T,
|
||||||
|
y: T,
|
||||||
|
}
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
struct Euclidian<T>
|
||||||
|
where
|
||||||
|
T: Integer,
|
||||||
|
{
|
||||||
|
x: T,
|
||||||
|
y: T,
|
||||||
|
z: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
type Table = Vec<Vec<char>>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
enum KartesianDirection {
|
||||||
|
TopLeft,
|
||||||
|
Top,
|
||||||
|
TopRight,
|
||||||
|
Left,
|
||||||
|
None,
|
||||||
|
Right,
|
||||||
|
BottomLeft,
|
||||||
|
Bottom,
|
||||||
|
BottomRight,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl KartesianDirection {
|
||||||
|
fn vector<T: Signed + Integer + Zero + From<i8>>(self) -> Kartesian<T> {
|
||||||
|
const BELOW: i8 = -1;
|
||||||
|
const ON: i8 = 0;
|
||||||
|
const UPPER: i8 = 1;
|
||||||
|
Kartesian::<T> {
|
||||||
|
x: match self {
|
||||||
|
Self::TopLeft | Self::Left | Self::BottomLeft => BELOW.into(),
|
||||||
|
Self::Top | Self::None | Self::Bottom => ON.into(),
|
||||||
|
Self::TopRight | Self::Right | Self::BottomRight => UPPER.into(),
|
||||||
|
},
|
||||||
|
y: match self {
|
||||||
|
Self::TopLeft | Self::Top | Self::TopRight => BELOW.into(),
|
||||||
|
Self::Left | Self::None | Self::Right => ON.into(),
|
||||||
|
Self::BottomLeft | Self::Bottom | Self::BottomRight => UPPER.into(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -156,3 +156,12 @@ pub fn get_string_numbers(input: &str) -> Vec<u32> {
|
||||||
}
|
}
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn line_to_char(line: &str) -> Vec<char> {
|
||||||
|
Vec::from_iter(line.chars())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn convert_to_array<T, F: FnMut(&str) -> T>(input: &str, func: F) -> Vec<T> {
|
||||||
|
input.split('\n').map(func).collect()
|
||||||
|
}
|
||||||
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren