Files
advent-of-code-2024/10/HoofIt/Program.cs
T

34 lines
737 B
C#
Raw Normal View History

2024-12-10 14:05:20 -06:00
using System.Diagnostics;
2024-12-10 20:52:40 -06:00
using HoofIt;
2024-12-10 14:05:20 -06:00
if (args.Length is 0)
{
Console.WriteLine("Please provide a path to the input file.");
return;
}
if (File.Exists(args[0]) is false)
{
Console.WriteLine("The provided file does not exist.");
return;
}
var isPart2 = args.Length is 2 && args[1] is "part2";
var input = await File.ReadAllLinesAsync(args[0]);
var stopwatch = new Stopwatch();
stopwatch.Start();
var map = TopoMap.From(input);
2024-12-10 20:52:40 -06:00
var nums = isPart2
? map.GetTrailheadRatings()
: map.GetTrailheadScores();
2024-12-10 14:05:20 -06:00
2024-12-10 20:52:40 -06:00
var result = nums.Sum();
2024-12-10 14:05:20 -06:00
2024-12-10 20:52:40 -06:00
var nameOfStat = isPart2 ? "ratings" : "scores";
2024-12-10 14:05:20 -06:00
stopwatch.Stop();
2024-12-10 20:52:40 -06:00
Console.WriteLine($"The sum of the {nameOfStat} of all trailheads is {result}. ({stopwatch.ElapsedMilliseconds}ms)");