mirror of
https://github.com/parnic/advent-of-code-2023.git
synced 2025-06-16 16:50:14 -05:00
Improve day 14 part 2 runtime
I realized I was looking for the third occurrence when the second works just as well.
This commit is contained in:
@ -164,10 +164,10 @@ internal class Day14 : Day
|
|||||||
Tilt(part2, eastDir);
|
Tilt(part2, eastDir);
|
||||||
|
|
||||||
var result = Stringify(part2);
|
var result = Stringify(part2);
|
||||||
if (seen.Count(g => g == result) == 2)
|
if (seen.Any(g => g == result))
|
||||||
{
|
{
|
||||||
int periodStart = seen.FindIndex(g => g == result);
|
int periodStart = seen.FindIndex(g => g == result);
|
||||||
int periodLen = seen.Skip(periodStart + 1).ToList().FindIndex(g => g == result) + 1;
|
int periodLen = seen.Count - periodStart;
|
||||||
loopCycle = ((1000000000L - periodStart) % periodLen) + periodStart;
|
loopCycle = ((1000000000L - periodStart) % periodLen) + periodStart;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user