aoc8
This commit is contained in:
parent
fd853da84e
commit
b0bde44ff4
@ -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]
|
||||
|
||||
15
benches/bench_aoc_8.rs
Normal file
15
benches/bench_aoc_8.rs
Normal file
@ -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);
|
||||
@ -5,3 +5,4 @@ pub mod aoc_4;
|
||||
pub mod aoc_5;
|
||||
pub mod aoc_6;
|
||||
pub mod aoc_7;
|
||||
pub mod aoc_8;
|
||||
|
||||
56
src/aoc/aoc_8.rs
Normal file
56
src/aoc/aoc_8.rs
Normal file
@ -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::<i64>()).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<[i64;3]>> = 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
|
||||
}
|
||||
20
src/aoc/input/test_input_aoc8.txt
Normal file
20
src/aoc/input/test_input_aoc8.txt
Normal file
@ -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
|
||||
@ -1,2 +1,3 @@
|
||||
#![feature(portable_simd)]
|
||||
#![feature(exact_length_collection)]
|
||||
pub mod aoc;
|
||||
|
||||
15
src/main.rs
15
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]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user