Files
advent-of-code-2024/12/GardenGroups/Program.cs
T

29 lines
694 B
C#
Raw Normal View History

2024-12-13 09:03:40 -06:00
using System.Diagnostics;
2024-12-13 22:01:35 -06:00
using GardenGroups;
2024-12-13 09:03:40 -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();
2024-12-13 22:01:35 -06:00
var garden = Garden.From(input);
var result = isPart2
? garden.CalculateFencePriceBasedOnSides()
: garden.CalculateFencePriceBasedOnPerimeter();
2024-12-13 09:03:40 -06:00
stopwatch.Stop();
2024-12-13 22:01:35 -06:00
Console.WriteLine($"The total cost to fence the garden is {result}. ({stopwatch.ElapsedMilliseconds}ms)");