Untitled
unknown
csharp
2 years ago
1.4 kB
10
Indexable
public abstract class Day2
{
private static int GetPower(string line)
{
var minimums = new Dictionary<string, int>
{
["red"] = int.MinValue,
["green"] = int.MinValue,
["blue"] = int.MinValue
};
var newStr = line.Split(":")[1];
var newLines = newStr.Split(";");
foreach (var newLine in newLines)
{
foreach (var val in newLine.Split(","))
{
var splitStr = val[1..].Split(" ");
var currColor = splitStr[1];
var currCount = int.Parse(splitStr[0]);
// Console.WriteLine(currColor + " " + currCount);
minimums[currColor] = int.Max(minimums[currColor], currCount);
}
}
// foreach (var kvp in minimums)
// {
// Console.Write(kvp.Key + " = " + kvp.Value + " ");
// }
// Console.WriteLine();
var list = minimums.Values.ToList();
return list.Aggregate(1, (current, power) => current * power);
}
public static int Part2()
{
return GetLines(InputFile).Sum(GetPower);
}
}Editor is loading...
Leave a Comment