Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaKateryna committed Dec 13, 2023
1 parent 87d6a42 commit 789bdff
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions AdventOfCode/Day12.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,23 @@ private int GetPossibleArrangements(char[] spring, List<int> 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
{
Expand Down

0 comments on commit 789bdff

Please sign in to comment.