mirror of
https://github.com/Baipyrus/AoC-23.git
synced 2024-12-26 12:01:45 +00:00
Compare commits
4 Commits
29e043f06c
...
633e1a8566
Author | SHA1 | Date | |
---|---|---|---|
633e1a8566 | |||
5cf79c7fe2 | |||
30f9c1bf88 | |||
2abb8a6d49 |
66
Cargo.lock
generated
66
Cargo.lock
generated
@ -15,75 +15,15 @@ dependencies = [
|
||||
name = "aoc-23"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.152"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.3"
|
||||
@ -112,9 +52,3 @@ name = "regex-syntax"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
@ -6,5 +6,4 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
||||
regex = "1.10.3"
|
||||
|
@ -30,3 +30,18 @@ pub fn split_inputs(input: Vec<String>, re: &str) -> Vec<Vec<String>> {
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn convert_num(input: Vec<Vec<String>>) -> Vec<Vec<i32>> {
|
||||
input
|
||||
.into_iter()
|
||||
.map(|a| {
|
||||
a
|
||||
.into_iter()
|
||||
.map(|b| {
|
||||
b
|
||||
.trim()
|
||||
.parse::<i32>()
|
||||
.expect("Invalid numeric value in input!")
|
||||
}).collect()
|
||||
}).collect()
|
||||
}
|
||||
|
@ -1,14 +1,50 @@
|
||||
use crate::common::{read_file, split_inputs, split_lines};
|
||||
use crate::common::{convert_num, read_file, split_inputs, split_lines};
|
||||
|
||||
pub fn main() {
|
||||
let name = "day9";
|
||||
let name = "day09";
|
||||
println!("Executing module '{name}' entrypoint . . . ");
|
||||
|
||||
let content = read_file(name);
|
||||
let lines = split_lines(&content);
|
||||
let input = split_inputs(lines, &r"\s+");
|
||||
|
||||
for value in &input[0] {
|
||||
print!("{value}, ");
|
||||
let sequences = convert_num(input);
|
||||
let structures: Vec<Vec<Vec<i32>>> = sequences
|
||||
.iter()
|
||||
.map(|s| extrapolate(s.to_vec()))
|
||||
.collect();
|
||||
|
||||
for seq in structures[0].clone() {
|
||||
for n in seq {
|
||||
print!("{n} ");
|
||||
}
|
||||
println!("");
|
||||
}
|
||||
}
|
||||
|
||||
fn extrapolate(seq: Vec<i32>) -> Vec<Vec<i32>> {
|
||||
let mut structure = vec![seq];
|
||||
let mut index = 0;
|
||||
|
||||
loop {
|
||||
let current = &structure[index];
|
||||
let diff = seq_diff(current.to_vec());
|
||||
|
||||
if diff.iter().all(|&n| n == 0) {
|
||||
break structure;
|
||||
}
|
||||
|
||||
structure.push(diff);
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn seq_diff(seq: Vec<i32>) -> Vec<i32> {
|
||||
let mut diff = Vec::new();
|
||||
|
||||
for (i, n) in seq.iter().skip(1).enumerate() {
|
||||
diff.push(n - seq[i]);
|
||||
}
|
||||
|
||||
diff
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
mod common;
|
||||
mod day9;
|
||||
mod day09;
|
||||
|
||||
fn main() {
|
||||
println!("Executing main entrypoint . . . ");
|
||||
day9::main();
|
||||
day09::main();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user