Replace for loops
This commit is contained in:
parent
5b1f405183
commit
d3cd5d777e
@ -19,29 +19,21 @@ fn is_safe(report: &[u32]) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn part1(parsed_input: &[Vec<u32>]) -> u32 {
|
fn part1(parsed_input: &[Vec<u32>]) -> u32 {
|
||||||
parsed_input
|
parsed_input.iter().filter(|report| is_safe(report)).count() as u32
|
||||||
.iter()
|
|
||||||
.filter(|report| is_safe(report))
|
|
||||||
.count() as u32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(parsed_input: &[Vec<u32>]) -> u32 {
|
fn part2(parsed_input: &[Vec<u32>]) -> u32 {
|
||||||
let mut res = 0;
|
parsed_input
|
||||||
for report in parsed_input {
|
.iter()
|
||||||
if is_safe(report) {
|
.filter(|report| {
|
||||||
res += 1;
|
is_safe(report)
|
||||||
continue;
|
|| (0..report.len()).any(|idx| {
|
||||||
}
|
let mut modified_report = (*report).clone();
|
||||||
for idx in 0..report.len() {
|
|
||||||
let mut modified_report = report.clone();
|
|
||||||
modified_report.remove(idx);
|
modified_report.remove(idx);
|
||||||
if is_safe(&modified_report) {
|
is_safe(&modified_report)
|
||||||
res += 1;
|
})
|
||||||
break;
|
})
|
||||||
}
|
.count() as u32
|
||||||
}
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user