| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System.Diagnostics;
- using Day15;
- if (args.Any(a => a == "--debug"))
- {
- Console.WriteLine("DEBUG");
- Console.WriteLine(Debugger.Launch());
- }
- if (args.Length < 1)
- {
- Console.WriteLine("Requires 1 args: inputFileName");
- return -1;
- }
- var inputFile = args[0];
- var parser = new Parser();
- var steps = parser.Parse(inputFile).ToList();
- var sum = 0;
- foreach (var s in steps)
- {
- var hash = s.GetHash();
- sum += hash;
- }
- Console.WriteLine();
- Console.WriteLine($"Total: {sum}");
- var boxes = Enumerable.Range(0, 256).Select(_ => new List<Lens>()).ToList();
- foreach (var s in steps)
- {
- s.Execute(boxes);
- foreach (var pair in boxes.Select((box, index) => (Box: box, Index: index)))
- {
- if (pair.Box.Count > 0)
- {
- var contents = string.Join(" ", pair.Box.Select(lens => lens.Visual()));
- Console.WriteLine($"Box {pair.Index}: {contents}");
- }
- }
- Console.WriteLine("-----");
- }
- var power = boxes
- .SelectMany((box, boxIndex) => box.Select((lens, lensIndex) => (boxIndex + 1) * (lensIndex + 1) * lens.FocalLength))
- .Sum();
- Console.WriteLine();
- Console.WriteLine($"Power: {power}");
- return 0;
|