Refactor Day10 to rename variables for consistency and add `.ToArray()` in `ParsePuzzleInputUnoptimized` to optimize LINQ evaluation
This commit is contained in:
parent
801b96de1d
commit
d92293f631
|
|
@ -120,7 +120,8 @@ public class Day10 : IPuzzleSolver<long>
|
|||
{
|
||||
var instructions = ParsePuzzleInputUnoptimized(pathToPuzzleInput);
|
||||
var minCounts = instructions
|
||||
.Select(instruction => GetMinCountButtonPressesForJoltageLevels(instruction.joltages, instruction.buttons));
|
||||
.Select(instruction => GetMinCountButtonPressesForJoltageLevels(instruction.joltages, instruction.buttons))
|
||||
.ToArray();
|
||||
return minCounts.Sum();
|
||||
}
|
||||
|
||||
|
|
@ -193,10 +194,10 @@ public class Day10 : IPuzzleSolver<long>
|
|||
.Zip(targetJoltages, (pJolt, tJolt) => (pJolt % 2) == (tJolt % 2))
|
||||
.All(isEqual => isEqual))
|
||||
.ToArray();
|
||||
foreach (var (joltageLevel, buttonPresses) in patternsToCheck)
|
||||
foreach (var (joltageLevels, cost) in patternsToCheck)
|
||||
{
|
||||
var nextPattern = targetJoltages.Zip(joltageLevel, (jolts, level) => (jolts - level) / 2).ToArray();
|
||||
var resultNext = 2 * GetMinCountInternal(nextPattern, patternCosts, memory) + buttonPresses;
|
||||
var nextPattern = targetJoltages.Zip(joltageLevels, (jolts, level) => (jolts - level) / 2).ToArray();
|
||||
var resultNext = 2 * GetMinCountInternal(nextPattern, patternCosts, memory) + cost;
|
||||
if (resultNext < minCount)
|
||||
{
|
||||
minCount = resultNext;
|
||||
|
|
|
|||
Loading…
Reference in New Issue