Пример #1
0
        static async Task Main(string[] args)
        {
            var code    = File.ReadLines(args.FirstOrDefault() ?? "input.txt").First();
            var program = IntcodeMachine.ParseCode(code);

            // Part 1
            var painted = await RunRobotAsync(program);

            var totalPaintedSquares = painted.Count;

            Console.WriteLine($"Part 1 Result = {totalPaintedSquares}");
            Console.WriteLine();

            // Part 2
            var pixels = await RunRobotAsync(program, initialColor : 1);

            var image = GenerateImage(pixels);

            Console.WriteLine("Part 2 Image:");
            foreach (var row in image)
            {
                Console.WriteLine(row);
            }

            Console.WriteLine();
        }
Пример #2
0
 public static async Task RunProgramAsync(
     long[] program,
     Func <CancellationToken, ValueTask <long> > read,
     Func <long, CancellationToken, ValueTask> write,
     CancellationToken cancellationToken = default)
 {
     var vm = new IntcodeMachine(program, read, write);
     await vm.StepUntilHalted(cancellationToken);
 }