Files
advent-of-code-2024/06/GuardGallivant/Program.cs
T

33 lines
776 B
C#
Raw Normal View History

2024-12-06 14:26:48 -06:00
using System.Diagnostics;
2024-12-07 01:28:15 -06:00
using GuardGallivant;
2024-12-06 14:26:48 -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";
2024-12-07 01:28:15 -06:00
var input = await File.ReadAllLinesAsync(args[0]);
2024-12-06 14:26:48 -06:00
var stopwatch = new Stopwatch();
stopwatch.Start();
2024-12-07 01:28:15 -06:00
var map = new Map(input);
var result = isPart2
? map.IdentifyNumberOfPlacementsForNewObstruction()
: map.PredictDistinctPositionsCount();
var msg = isPart2
? $"There are {result} positions for the new obstruction"
: $"The guard will visit {result} positions";
2024-12-06 14:26:48 -06:00
stopwatch.Stop();
2024-12-07 01:28:15 -06:00
Console.WriteLine($"{msg}. ({stopwatch.ElapsedMilliseconds}ms)");