37 lines
1010 B
C#
37 lines
1010 B
C#
using AdvenOfCode.Contracts;
|
|
|
|
namespace AoC_2026;
|
|
|
|
public class Day01 : IPuzzleSolver<long>
|
|
{
|
|
private int[] ParsePuzzleInput(string path)
|
|
{
|
|
var puzzleInput = File.ReadAllLines(path)
|
|
.Where(l => !string.IsNullOrWhiteSpace(l))
|
|
.Select(l => int.Parse(l))
|
|
.ToArray();
|
|
return puzzleInput;
|
|
}
|
|
|
|
public long SolvePart1(string pathToPuzzleInput)
|
|
{
|
|
var input = ParsePuzzleInput(pathToPuzzleInput);
|
|
var result = input
|
|
.GroupBy(id => id)
|
|
.OrderByDescending(g => g.Count())
|
|
.Take(3)
|
|
.Aggregate(1L, (agg, next) => agg * next.Key);
|
|
return result;
|
|
}
|
|
|
|
public long SolvePart2(string pathToPuzzleInput)
|
|
{
|
|
var input = ParsePuzzleInput(pathToPuzzleInput);
|
|
var result = input
|
|
.GroupBy(id => id)
|
|
.OrderBy(g => g.Count())
|
|
.Take(3)
|
|
.Aggregate(1L, (agg, next) => agg * next.Key);
|
|
return result;
|
|
}
|
|
} |