From d2a17216c79941b008018d86a8f8f139892224e3 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Mon, 25 Dec 2023 22:09:27 +0100 Subject: [PATCH] Flip check order --- 2023/src/day24.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/2023/src/day24.rs b/2023/src/day24.rs index defc3aa..18591a5 100644 --- a/2023/src/day24.rs +++ b/2023/src/day24.rs @@ -41,15 +41,14 @@ impl Hail { let x = b / a; let y = a1 * x + b1; - let t1 = (x - self.position[0] as f64) / self.speed[0] as f64; - let t2 = (x - other.position[0] as f64) / other.speed[0] as f64; - - if t1 < 0.0 || t2 < 0.0 { + if x < min || x > max || y < min || y > max { return false; } - // use the formula for X - x >= min && x <= max && y >= min && y <= max + let t1 = (x - self.position[0] as f64) / self.speed[0] as f64; + let t2 = (x - other.position[0] as f64) / other.speed[0] as f64; + + t1 >= 0.0 && t2 >= 0.0 } fn parse(i: &[u8]) -> IResult<&[u8], Self> {