diff options
author | Guillermo Ramos | 2024-12-02 23:29:43 +0100 |
---|---|---|
committer | Guillermo Ramos | 2024-12-02 23:29:43 +0100 |
commit | ae55e01cd8307f8fb75e7482ff216c2738fd2cd1 (patch) | |
tree | 742d29e67ff63bc8546c0bfd7c601c9b1d5c91f9 /2024/2/p2.rs | |
parent | d69b3025ffe15cc38844704c79a8fa23fe96f09b (diff) | |
download | AoC-ae55e01cd8307f8fb75e7482ff216c2738fd2cd1.tar.gz |
rustfmt
Diffstat (limited to '2024/2/p2.rs')
-rw-r--r-- | 2024/2/p2.rs | 16 |
1 files changed, 10 insertions, 6 deletions
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<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) || is_safe_with_dampener(&levels) { total += 1; } |