Day 2-2
This commit is contained in:
parent
b4fb2f0643
commit
664266054c
@ -137,7 +137,7 @@ public static class Day2
|
|||||||
|
|
||||||
while (TryReadLine(ref buffer, out var line))
|
while (TryReadLine(ref buffer, out var line))
|
||||||
{
|
{
|
||||||
sum += ProcessLine(line, gameSettings);
|
sum += ProcessLine2(line, gameSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.AdvanceTo(buffer.Start, buffer.End);
|
reader.AdvanceTo(buffer.Start, buffer.End);
|
||||||
@ -200,6 +200,39 @@ public static class Day2
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int ProcessLine2(ReadOnlySequence<byte> line, GameSettings gameSettings)
|
||||||
|
{
|
||||||
|
var str = Encoding.UTF8.GetString(line);
|
||||||
|
if (string.IsNullOrWhiteSpace(str))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
var game = ParseString(str);
|
||||||
|
GameSet minGameSet = default;
|
||||||
|
foreach (var gameSets in game.Games.Values)
|
||||||
|
{
|
||||||
|
foreach (var gameSet in gameSets)
|
||||||
|
{
|
||||||
|
if (gameSet.Red > minGameSet.Red)
|
||||||
|
{
|
||||||
|
minGameSet.Red = gameSet.Red;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gameSet.Blue > minGameSet.Blue)
|
||||||
|
{
|
||||||
|
minGameSet.Blue = gameSet.Blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gameSet.Green > minGameSet.Green)
|
||||||
|
{
|
||||||
|
minGameSet.Green = gameSet.Green;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return minGameSet.Red * minGameSet.Green * minGameSet.Blue;
|
||||||
|
}
|
||||||
|
|
||||||
public static GameData ParseString(string str)
|
public static GameData ParseString(string str)
|
||||||
{
|
{
|
||||||
var strSpan = str.AsSpan();
|
var strSpan = str.AsSpan();
|
||||||
|
Loading…
Reference in New Issue
Block a user