From 1274eee16b2985ff463dd53e9a1e7cd86709ba6d Mon Sep 17 00:00:00 2001 From: Tom-the-Bomb Date: Fri, 5 Jan 2024 13:56:05 -0500 Subject: [PATCH] fix --- Cargo.lock | 12 ++++++------ src/bin/day24.rs | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e757392..090e450 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,9 +340,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.74" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] @@ -477,7 +477,7 @@ checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -506,9 +506,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.46" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -566,5 +566,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] diff --git a/src/bin/day24.rs b/src/bin/day24.rs index 19e4d61..163438a 100644 --- a/src/bin/day24.rs +++ b/src/bin/day24.rs @@ -27,16 +27,16 @@ struct Hailstone { z_vel: f64, } -type BF1024 = BigFloat>; +type BF128 = BigFloat>; #[derive(Debug, Clone, PartialEq)] struct BFHailstone { - x_pos: BF1024, - y_pos: BF1024, - z_pos: BF1024, - x_vel: BF1024, - y_vel: BF1024, - z_vel: BF1024, + x_pos: BF128, + y_pos: BF128, + z_pos: BF128, + x_vel: BF128, + y_vel: BF128, + z_vel: BF128, } macro_rules! parse_part { @@ -79,7 +79,7 @@ macro_rules! impl_from_str { } impl_from_str!(Hailstone, f64); -impl_from_str!(BFHailstone, BF1024); +impl_from_str!(BFHailstone, BF128); #[inline] fn float_cmp(a: f64, b: f64) -> bool { @@ -170,6 +170,10 @@ impl Day24 { .count() } + /// # Panics + /// + /// If failed to invert the `a` matrix + /// or failed to parse input lines pub fn part_two(&self, inp: T) -> usize { let inp = inp.to_string(); let mut hailstones = inp @@ -189,27 +193,27 @@ impl Day24 { let a = Matrix6::new( hs2.y_vel.clone() - hs1.y_vel.clone(), - hs1.x_vel.clone() - hs2.x_vel.clone(), BF1024::zero(), + hs1.x_vel.clone() - hs2.x_vel.clone(), BF128::zero(), hs1.y_pos.clone() - hs2.y_pos.clone(), - hs2.x_pos.clone() - hs1.x_pos.clone(), BF1024::zero(), + hs2.x_pos.clone() - hs1.x_pos.clone(), BF128::zero(), hs3.y_vel.clone() - hs1.y_vel.clone(), - hs1.x_vel.clone() - hs3.x_vel.clone(), BF1024::zero(), + hs1.x_vel.clone() - hs3.x_vel.clone(), BF128::zero(), hs1.y_pos.clone() - hs3.y_pos.clone(), - hs3.x_pos.clone() - hs1.x_pos.clone(), BF1024::zero(), - hs2.z_vel.clone() - hs1.z_vel.clone(), BF1024::zero(), + hs3.x_pos.clone() - hs1.x_pos.clone(), BF128::zero(), + hs2.z_vel.clone() - hs1.z_vel.clone(), BF128::zero(), hs1.x_vel.clone() - hs2.x_vel.clone(), - hs1.z_pos.clone() - hs2.z_pos.clone(), BF1024::zero(), + hs1.z_pos.clone() - hs2.z_pos.clone(), BF128::zero(), hs2.x_pos.clone() - hs1.x_pos.clone(), - hs3.z_vel.clone() - hs1.z_vel.clone(), BF1024::zero(), + hs3.z_vel.clone() - hs1.z_vel.clone(), BF128::zero(), hs1.x_vel.clone() - hs3.x_vel.clone(), - hs1.z_pos.clone() - hs3.z_pos.clone(), BF1024::zero(), + hs1.z_pos.clone() - hs3.z_pos.clone(), BF128::zero(), hs3.x_pos.clone() - hs1.x_pos.clone(), - BF1024::zero(), hs2.z_vel.clone() - hs1.z_vel.clone(), - hs1.y_vel.clone() - hs2.y_vel.clone(), BF1024::zero(), + BF128::zero(), hs2.z_vel.clone() - hs1.z_vel.clone(), + hs1.y_vel.clone() - hs2.y_vel.clone(), BF128::zero(), hs1.z_pos.clone() - hs2.z_pos.clone(), hs2.y_pos.clone() - hs1.y_pos.clone(), - BF1024::zero(), hs3.z_vel.clone() - hs1.z_vel.clone(), - hs1.y_vel.clone() - hs3.y_vel.clone(), BF1024::zero(), + BF128::zero(), hs3.z_vel.clone() - hs1.z_vel.clone(), + hs1.y_vel.clone() - hs3.y_vel.clone(), BF128::zero(), hs1.z_pos.clone() - hs3.z_pos.clone(), hs3.y_pos.clone() - hs1.y_pos.clone(), ); @@ -234,6 +238,7 @@ impl Day24 { - (hs1.y_pos * hs1.z_vel - hs3.y_pos * hs3.z_vel), ); + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] a .try_inverse() .map(|a_inverse| {