36 lines
951 B
C#
36 lines
951 B
C#
|
namespace AdventOfCode2022.Handlers
|
||
|
{
|
||
|
public class Day01
|
||
|
{
|
||
|
string[] elves;
|
||
|
IEnumerable<int> caloriesPerElf;
|
||
|
|
||
|
public Day01()
|
||
|
{
|
||
|
var lines = System.IO.File.ReadAllText(@"./days/01/input");
|
||
|
elves = lines.Split("\n\n");
|
||
|
caloriesPerElf = elves.Select(ParseCalories);
|
||
|
}
|
||
|
|
||
|
private int ParseCalories(string elf)
|
||
|
{
|
||
|
return elf.Split("\n")
|
||
|
.Where(calorie => !string.IsNullOrWhiteSpace(calorie))
|
||
|
.Select(int.Parse)
|
||
|
.Sum();
|
||
|
}
|
||
|
|
||
|
|
||
|
public void PartA()
|
||
|
{
|
||
|
var max = caloriesPerElf.Max();
|
||
|
Console.WriteLine($"Highest calories: {max}");
|
||
|
}
|
||
|
|
||
|
public void PartB()
|
||
|
{
|
||
|
var topThree = caloriesPerElf.OrderByDescending(calories => calories).Take(3).Sum();
|
||
|
Console.WriteLine($"Top three calories: {topThree}");
|
||
|
}
|
||
|
}
|
||
|
}
|