Improved day 24 solution

This commit is contained in:
Dreaded_X 2023-12-25 01:01:29 +01:00
parent 6233ade178
commit 7951f60e7f
Signed by: Dreaded_X
GPG Key ID: 5A0CBFE3C3377FAA

View File

@ -113,8 +113,6 @@ fn mode(numbers: &[usize]) -> usize {
*occurrences.entry(value).or_insert(0) += 1; *occurrences.entry(value).or_insert(0) += 1;
} }
println!("{occurrences:?}");
occurrences occurrences
.into_iter() .into_iter()
.max_by_key(|&(_, count)| count) .max_by_key(|&(_, count)| count)
@ -207,9 +205,6 @@ impl aoc::Solver for Day {
-c8, -c12, 0.0, -c8, -c12, 0.0,
); );
// Get the inverse of the matrix
let inverse = matrix.try_inverse().unwrap();
// Constant on the rhs // Constant on the rhs
let k1 = let k1 =
h[i].py * h[i].vz - h[j].py * h[j].vz + h[j].pz * h[j].vy - h[i].pz * h[i].vy; h[i].py * h[i].vz - h[j].py * h[j].vz + h[j].pz * h[j].vy - h[i].pz * h[i].vy;
@ -227,8 +222,7 @@ impl aoc::Solver for Day {
// Put them into a vector // Put them into a vector
let k = Vector6::new(k1, k2, k3, k4, k5, k6); let k = Vector6::new(k1, k2, k3, k4, k5, k6);
// Calclate the solution let solution = matrix.lu().solve(&k).unwrap();
let solution = inverse * k;
// The sum of all elements of the starting position is the answer // The sum of all elements of the starting position is the answer
(solution[0] + solution[1] + solution[2]).round() as usize (solution[0] + solution[1] + solution[2]).round() as usize