Added early abort if there are too many damaged springs in a row
This commit is contained in:
parent
250417760b
commit
86202a10e6
|
@ -154,10 +154,15 @@ fn count_valid(
|
||||||
a + b
|
a + b
|
||||||
}
|
}
|
||||||
Spring::Damaged => {
|
Spring::Damaged => {
|
||||||
|
if damaged_chain + 1 > list[0] {
|
||||||
|
// The chain is to long
|
||||||
|
0
|
||||||
|
} else {
|
||||||
// Add to the damaged chain
|
// Add to the damaged chain
|
||||||
count_valid(&mut springs[1..], list, damaged_chain + 1, cache)
|
count_valid(&mut springs[1..], list, damaged_chain + 1, cache)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(cache) = cache {
|
if let Some(cache) = cache {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user