From 86202a10e661abc8c2faa190dc0ad0e82a327448 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Tue, 12 Dec 2023 14:55:31 +0100 Subject: [PATCH] Added early abort if there are too many damaged springs in a row --- 2023/src/bin/day12.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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) + } } } };