Beispiel #1
0
        static void Main(string[] args)
        {
            if (args.Any())
            {
                var program = IntcodeMachine.ParseCode(File.ReadLines(args.First()).First());

                // Part 1
                Console.WriteLine("Part 1:");
                IntcodeMachine.RunProgram(
                    program,
                    () => 1,
                    WriteToConsole
                    );

                Console.WriteLine();

                // Part 2
                Console.WriteLine("Part 2:");
                IntcodeMachine.RunProgram(
                    program,
                    () => 2,
                    WriteToConsole
                    );
            }
            else
            {
                RunTests();
            }
        }
Beispiel #2
0
        private static void RunTests()
        {
            var testPrograms = new[] {
                "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99",
                "1102,34915192,34915192,7,4,7,99,0",
                "104,1125899906842624,99"
            };

            var count = 0;

            foreach (var code in testPrograms)
            {
                try
                {
                    Console.WriteLine($"Test #{++count}");

                    var program = IntcodeMachine.ParseCode(code);
                    IntcodeMachine.RunProgram(
                        program,
                        ReadConsoleInput,
                        WriteToConsole
                        );
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    Console.WriteLine();
                }
            }
        }