From 789bdffcf3b1329d8610eb4173e6398f9d2c14f5 Mon Sep 17 00:00:00 2001 From: KaterynaKateryna Date: Wed, 13 Dec 2023 19:54:17 +0100 Subject: [PATCH] optimize --- AdventOfCode/Day12.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/AdventOfCode/Day12.cs b/AdventOfCode/Day12.cs index 67df01f..c17eaac 100644 --- a/AdventOfCode/Day12.cs +++ b/AdventOfCode/Day12.cs @@ -89,22 +89,23 @@ private int GetPossibleArrangements(char[] spring, List groups, int index = if (spring[index] == '?') { - char[] option = spring.ToArray(); - option[index] = '#'; - (bool isValid, int newIndex) = IsValid(option, groups, index, curGroupIndex); + spring[index] = '#'; + (bool isValid, int newIndex) = IsValid(spring, groups, index, curGroupIndex); if (isValid) { - int a = GetPossibleArrangements(option, groups, index + 1, newIndex); + int a = GetPossibleArrangements(spring, groups, index + 1, newIndex); count += a; } - option[index] = '.'; - (isValid, newIndex) = IsValid(option, groups, index, curGroupIndex); + spring[index] = '.'; + (isValid, newIndex) = IsValid(spring, groups, index, curGroupIndex); if (isValid) { - int b = GetPossibleArrangements(option, groups, index + 1, newIndex); + int b = GetPossibleArrangements(spring, groups, index + 1, newIndex); count += b; } + + spring[index] = '?'; } else {