feat: complete day 2

This commit is contained in:
Stevan Freeborn
2024-12-05 00:40:13 -06:00
parent 4f723c8eb4
commit ad0830f789
3 changed files with 240 additions and 2 deletions
+30 -2
View File
@@ -1,2 +1,30 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using System.Diagnostics;
using CeresSearch;
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 grid = new Grid(input);
var results = isPart2
? grid.CountXmases()
: grid.CountOccurrences("XMAS");
stopwatch.Stop();
Console.WriteLine($"The number of occurrences is {results}. ({stopwatch.ElapsedMilliseconds}ms)");