diff --git a/Cargo.toml b/Cargo.toml index 19d7abf..f9363ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,10 @@ harness = false name = "bench_aoc_7" harness = false +[[bench]] +name = "bench_aoc_8" +harness = false + [dependencies] bstr = "1.12.1" [profile.bench] diff --git a/benches/bench_aoc_8.rs b/benches/bench_aoc_8.rs new file mode 100644 index 0000000..553f638 --- /dev/null +++ b/benches/bench_aoc_8.rs @@ -0,0 +1,15 @@ +use std::hint::black_box; +use criterion::{criterion_group, criterion_main, Criterion}; +use aoc2025::aoc::aoc_8; + +fn bench_aoc_8_part1(c: &mut Criterion) { + let input = black_box(include_str!("../src/aoc/input/full_input_aoc8.txt")); + c.bench_function("bench_aoc8 part 1", |b| b.iter(|| aoc_8::solve_p1(input))); +} + + +criterion_group!( + benches_p8, + bench_aoc_8_part1, +); +criterion_main!(benches_p8); \ No newline at end of file diff --git a/src/aoc.rs b/src/aoc.rs index 4f33f99..498a907 100644 --- a/src/aoc.rs +++ b/src/aoc.rs @@ -5,3 +5,4 @@ pub mod aoc_4; pub mod aoc_5; pub mod aoc_6; pub mod aoc_7; +pub mod aoc_8; diff --git a/src/aoc/aoc_8.rs b/src/aoc/aoc_8.rs new file mode 100644 index 0000000..aabf2a0 --- /dev/null +++ b/src/aoc/aoc_8.rs @@ -0,0 +1,56 @@ + + + +pub fn solve_p1(input: &str) -> u64 { + let mut answer = 0; + let mut cords = Vec::new(); + for line in input.lines() { + let data = line.split(',').flat_map(|d| d.parse::()).collect_array::<3>().unwrap(); + cords.push(data); + } + //println!("{:?}", cords); + + let mut closest:Vec<[i64; 3]> = Vec::new(); + let mut pairs:Vec<([i64;3], [i64;3])> = Vec::new(); + for i in 0..cords.len() { + let mut distance = i64::MAX;; + for j in 0..cords.len() { + if i != j { + let distance_x = cords[i][0] - cords[j][0]; + let distance_y = cords[i][1] - cords[j][1]; + let distance_z = cords[i][2] - cords[j][2]; + let new_distance = ((distance_x.pow(2) + distance_y.pow(2)) + distance_z.pow(2)).isqrt() ; + if new_distance < distance { + distance = new_distance; + if i < closest.len() { + closest[i] = cords[j]; + } else { + closest.insert(i, cords[j]); + } + + } + } + } + } + for i in 0..closest.len() { + if !pairs.contains(&(cords[i], closest[i])) && !pairs.contains(&(closest[i], cords[i])) { + if cords[i][0] < closest[i][0] { + pairs.push((cords[i], closest[i])); + } else { + pairs.push((closest[i], cords[i])); + } + + } + + } + pairs.sort_unstable(); + //vec of vecs containing all cords combined together + let mut circuits: Vec> = Vec::new(); + //circuits[0].push(pairs[0].0); + for i in 0..pairs.len() { + + } + // make tree, insert data check if cord in tree + //println!("{:?}", pairs); + answer +} \ No newline at end of file diff --git a/src/aoc/input/test_input_aoc8.txt b/src/aoc/input/test_input_aoc8.txt new file mode 100644 index 0000000..20c6fd2 --- /dev/null +++ b/src/aoc/input/test_input_aoc8.txt @@ -0,0 +1,20 @@ +162,817,812 +57,618,57 +906,360,560 +592,479,940 +352,342,300 +466,668,158 +542,29,236 +431,825,988 +739,650,466 +52,470,668 +216,146,977 +819,987,18 +117,168,530 +805,96,715 +346,949,466 +970,615,88 +941,993,340 +862,61,35 +984,92,344 +425,690,689 \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 1f98310..0a30b9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,3 @@ #![feature(portable_simd)] +#![feature(exact_length_collection)] pub mod aoc; diff --git a/src/main.rs b/src/main.rs index f4326c2..b515915 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,8 @@ -#![feature(portable_simd)] // Enable the nightly feature +#![feature(portable_simd)] +#![feature(exact_length_collection)] +extern crate core; + +// Enable the nightly feature pub mod aoc; use crate::aoc::*; @@ -42,14 +46,17 @@ fn main() { println!("answer: {}", answer); */ - + /* let input = include_str!("aoc/input/full_input_aoc7.txt"); let answer = aoc_7::solve_p1(input); println!("answer: {}", answer); - let input = include_str!("aoc/input/full_input_aoc7.txt"); + let input = include_bytes!("aoc/input/full_input_aoc7.txt"); let answer = aoc_7::solve_p2(input); println!("answer: {}", answer); - + */ + let input = include_str!("aoc/input/test_input_aoc8.txt"); + let answer = aoc_8::solve_p1(input); + println!("answer: {}", answer); } #[test]