44 lines
911 B
C#
44 lines
911 B
C#
string[] data = await File.ReadAllLinesAsync("day-01-input.txt");
|
|
|
|
|
|
Console.WriteLine($"Max value: {GetPart2(data)}");
|
|
Console.ReadKey(true);
|
|
|
|
int GetPart1(string[] data)
|
|
{
|
|
int maxValue = 0, buffer = 0;
|
|
|
|
foreach (string value in data)
|
|
{
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
if (buffer > maxValue) maxValue = buffer;
|
|
buffer = 0;
|
|
continue;
|
|
}
|
|
|
|
buffer += Convert.ToInt32(value);
|
|
}
|
|
|
|
return maxValue;
|
|
}
|
|
|
|
int GetPart2(string[] data)
|
|
{
|
|
List<int> values = new List<int>();
|
|
int buffer = 0;
|
|
|
|
foreach (string value in data)
|
|
{
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
values.Add(buffer);
|
|
buffer = 0;
|
|
continue;
|
|
}
|
|
|
|
buffer += Convert.ToInt32(value);
|
|
}
|
|
|
|
return values.OrderByDescending(v => v).Take(3).Sum();
|
|
} |