Files

35 lines
878 B
C#
Raw Permalink Normal View History

2024-12-14 00:20:36 -06:00
using System.Diagnostics;
2024-12-14 12:58:28 -06:00
using ClawContraption;
2024-12-14 00:20:36 -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-14 12:58:28 -06:00
var input = await File.ReadAllTextAsync(args[0]);
2024-12-14 00:20:36 -06:00
var stopwatch = new Stopwatch();
stopwatch.Start();
2024-12-14 12:58:28 -06:00
var offset = isPart2 ? 10_000_000_000_000 : 0;
int? maxPresses = isPart2 ? null : 100;
var machines = input
.Split($"{Environment.NewLine}{Environment.NewLine}")
.Select(s => s.Split(Environment.NewLine))
.Select(s => Machine.From(s, maxPresses, offset))
.ToList();
var result = machines.Sum(m => m.TokenCost);
2024-12-14 00:20:36 -06:00
stopwatch.Stop();
2024-12-14 12:58:28 -06:00
Console.WriteLine($"The fewest tokens to when all possible games is {result}. ({stopwatch.ElapsedMilliseconds}ms)");