diff options
| author | nekineki <nekineki@nekineki.net> | 2024-12-03 10:23:57 +0100 |
|---|---|---|
| committer | nekineki <nekineki@nekineki.net> | 2024-12-03 10:23:57 +0100 |
| commit | ea583b8c165d9678e75c881e62beb828dac5dd5f (patch) | |
| tree | 9b5326772a4c803e70cad48d9e21e33b6f199735 /2024/day02.rs | |
| parent | b503d9bdd545232501ca9a34623edb8a324d49ae (diff) | |
update day02, day03
Diffstat (limited to '2024/day02.rs')
| -rw-r--r-- | 2024/day02.rs | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/2024/day02.rs b/2024/day02.rs index b573d5c..798df97 100644 --- a/2024/day02.rs +++ b/2024/day02.rs @@ -4,10 +4,8 @@ use std::env; use std::fs::File; use std::io::Read; +use itertools::Itertools; -fn is_all_same(arr: &[bool]) -> bool { - arr.windows(2).all(|w| w[0] == w[1]) -} fn is_safe(arr: &[i32]) -> bool { let diff: Vec<i32> = arr.windows(2).map(|w| w[0] - w[1]).collect(); @@ -15,7 +13,7 @@ fn is_safe(arr: &[i32]) -> bool { .iter() .map(|a| (3 >= a.abs()) && (a.abs() >= 1)) .all(|a| a); - let sign_ok = is_all_same(&diff.iter().map(|a| *a > 0).collect::<Vec<_>>()); + let sign_ok = diff.iter().map(|a| *a > 0).all_equal(); inc_ok && sign_ok } |
