diff options
Diffstat (limited to '2024/2/p1.rs')
-rw-r--r-- | 2024/2/p1.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/2024/2/p1.rs b/2024/2/p1.rs index 4e4df46..7c0abe3 100644 --- a/2024/2/p1.rs +++ b/2024/2/p1.rs @@ -10,9 +10,11 @@ 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) }; + 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 direction == Unknown { direction = d; } @@ -28,8 +30,10 @@ fn main() { let mut total = 0; for report in input.lines() { - let levels: Vec<u32> = - report.split_whitespace().map(|l| l.parse().unwrap()).collect(); + let levels: Vec<u32> = report + .split_whitespace() + .map(|l| l.parse().unwrap()) + .collect(); if is_safe(&levels) { total += 1; } |