From ae55e01cd8307f8fb75e7482ff216c2738fd2cd1 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Mon, 2 Dec 2024 23:29:43 +0100 Subject: rustfmt --- 2024/2/p2.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to '2024/2/p2.rs') diff --git a/2024/2/p2.rs b/2024/2/p2.rs index d21f102..78224c4 100644 --- a/2024/2/p2.rs +++ b/2024/2/p2.rs @@ -10,10 +10,12 @@ use Direction::*; fn is_safe(levels: &[u32]) -> bool { let mut direction = Unknown; - for i in 0..levels.len()-1 { - let [x, y] = levels[i..=i+1] else { panic!("unreachable") }; - let (diff, d) = if x > y { (x-y, Down) } else { (y-x, Up) }; - if direction == Unknown { + for i in 0..levels.len() - 1 { + let [x, y] = levels[i..=i + 1] else { + unreachable!() + }; + let (diff, d) = if x > y { (x - y, Down) } else { (y - x, Up) }; + if let Unknown = direction { direction = d; } if diff == 0 || diff > 3 || direction != d { @@ -39,8 +41,10 @@ fn main() { let mut total = 0; for report in input.lines() { - let levels: Vec = - report.split_whitespace().map(|l| l.parse().unwrap()).collect(); + let levels: Vec = report + .split_whitespace() + .map(|l| l.parse().unwrap()) + .collect(); if is_safe(&levels) || is_safe_with_dampener(&levels) { total += 1; } -- cgit v1.2.3