diff --git a/2023/src/bin/day12.rs b/2023/src/bin/day12.rs index 944f069..e47ed42 100644 --- a/2023/src/bin/day12.rs +++ b/2023/src/bin/day12.rs @@ -154,8 +154,13 @@ fn count_valid( a + b } Spring::Damaged => { - // Add to the damaged chain - count_valid(&mut springs[1..], list, damaged_chain+1, cache) + if damaged_chain + 1 > list[0] { + // The chain is to long + 0 + } else { + // Add to the damaged chain + count_valid(&mut springs[1..], list, damaged_chain + 1, cache) + } } } };