AdventOfCode2022/AOC2022/Puzzles/Day1.cs

43 lines
859 B
C#

namespace AOC2022.Puzzles;
internal class Day1 : IPuzzle
{
private readonly string[] _linesFromFile;
private readonly List<int> _elfFoodSumList = new();
public Day1(string[] linesFromFile)
{
_linesFromFile = linesFromFile;
GetElfFoodSumList();
}
private void GetElfFoodSumList()
{
var elfFoodSum = 0;
//var elfFoodSumList = new List<int>();
foreach (var line in _linesFromFile)
{
if (!string.IsNullOrWhiteSpace(line))
{
elfFoodSum += int.Parse(line);
}
else
{
_elfFoodSumList.Add(elfFoodSum);
elfFoodSum = 0;
}
_elfFoodSumList.Sort((x, y) => y.CompareTo(x));
}
}
public void SolveFirstPuzzle()
{
Console.WriteLine($"Fattest fucker has {_elfFoodSumList[0]} borgers");
}
public void SolveSecondPuzzle()
{
Console.WriteLine($"Top 3 Fatties have {_elfFoodSumList.Take(3).Sum()} borgers");
}
}