Day 13 - task 1
This commit is contained in:
parent
232a296638
commit
3d80103536
1 changed files with 5 additions and 22 deletions
|
@ -1,4 +1,4 @@
|
||||||
use std::fs;
|
use std::{fs, cmp::Ordering};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
pub fn solve() {
|
pub fn solve() {
|
||||||
|
@ -94,28 +94,11 @@ fn is_right_order(values: (&Value, &Value)) -> Ordered {
|
||||||
let left = left.unwrap();
|
let left = left.unwrap();
|
||||||
let right = right.unwrap();
|
let right = right.unwrap();
|
||||||
|
|
||||||
return is_right_order((&left, &right));
|
let res = is_right_order((&left, &right));
|
||||||
|
if res != Ordered::Maybe {
|
||||||
|
return res
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut current_order = Ordered::Maybe;
|
|
||||||
a0.iter()
|
|
||||||
.enumerate()
|
|
||||||
.for_each(|(i, _)| {
|
|
||||||
if current_order == Ordered::No
|
|
||||||
|| current_order == Ordered::Yes {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if a1.len() < i+1 {
|
|
||||||
current_order = Ordered::No;
|
|
||||||
println!("2nd arr too short");
|
|
||||||
return
|
|
||||||
}
|
|
||||||
current_order = is_right_order((&a0[i], &a1[i]));
|
|
||||||
});
|
|
||||||
if a0.len() > a1.len() && current_order != Ordered::No {
|
|
||||||
return Ordered::Yes
|
|
||||||
}
|
|
||||||
return current_order;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ordered::Yes
|
Ordered::Yes
|
||||||
|
|
Loading…
Reference in a new issue