From 3a8987fa4b8ccf5952c9cf831ced6688ef6b4281 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 17 Dec 2021 11:39:36 -0600 Subject: [PATCH] Day 17 part 2 --- 2021/rust/day17.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/2021/rust/day17.rs b/2021/rust/day17.rs index 47ab437..8e71da1 100644 --- a/2021/rust/day17.rs +++ b/2021/rust/day17.rs @@ -58,12 +58,14 @@ fn simulate_shot(initial_vel: Vec2, target: &Rect) -> Result<(Vec2, i64), (Vec2, Err((Vec2 { x, y }, last_pos)) } -fn trick_shot(r: &Rect) -> Option { +fn trick_shot(r: &Rect) -> (Option, i64) { let mut result = None; - for x in 1..=r.top_left.x { + let mut valid_shots = 0; + for x in 1..=r.bottom_right.x { for y in r.bottom_right.y..=2000 { println!("Simulating {}, {}", x, y); if let Ok((v, hy)) = simulate_shot(Vec2 { x, y }, r) { + valid_shots += 1; if result.is_some() { if hy > result.unwrap() { result = Some(hy); } } else { @@ -73,12 +75,12 @@ fn trick_shot(r: &Rect) -> Option { } } } - result + (result, valid_shots) } fn main() { let r = parse_target_rect(&day_input(17).trim()); - println!("Trick Shot Apex: {}", trick_shot(&r).unwrap()); + println!("Trick Shot Data: {:#?}", trick_shot(&r)); } #[cfg(test)]