Skip to content

Commit

Permalink
fix day 14
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaKateryna committed Dec 28, 2023
1 parent 586ee23 commit 2724cf8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions AdventOfCode/Day14.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,23 @@ public override ValueTask<string> Solve_1()

public override ValueTask<string> Solve_2()
{
HashSet<string> maps = new HashSet<string>();
List<string> maps = new List<string>();

string key = "";
do
string key = string.Join(Environment.NewLine, _input.Select(l => new string(l)));
while (!maps.Contains(key))
{
maps.Add(key);

Cycle();
key = string.Join(Environment.NewLine, _input.Select(l => new string(l)));
}
while (maps.Add(key));

int cycleStart = maps.IndexOf(key);
int cycleLength = maps.Count - cycleStart;

int rest = 1_000_000_000 % maps.Count;
int rest = (1_000_000_000 - maps.Count) % cycleLength;

for (int i = 0; i < rest - 1; ++i)
for (int i = 0; i < rest; ++i)
{
Cycle();
}
Expand Down

0 comments on commit 2724cf8

Please sign in to comment.