summaryrefslogtreecommitdiff
path: root/2024/2/p2.rs
diff options
context:
space:
mode:
Diffstat (limited to '2024/2/p2.rs')
-rw-r--r--2024/2/p2.rs16
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;
}