Example #1
0
        static void Main(string[] args)
        {
            IntcodeComputer comp  = new IntcodeComputer();
            string          input = File.ReadAllText("IntCode.txt");

            //string input = File.ReadAllText("IntCodeTests.txt");
            string[] programs = input.Split('\n');

            foreach (string p in programs)
            {
                Console.WriteLine(p);


                for (int i = 0; i < 100; i++)
                {
                    for (int j = 0; j < 100; j++)
                    {
                        try
                        {
                            var program = comp.Parse(p);
                            program[1] = i;
                            program[2] = j;
                            var result = comp.Run(program);
                            Console.WriteLine(i + " " + j + " " + result[0]);

                            if (result[0] == 19690720)
                            {
                                comp.Print(program);
                                return;
                            }
                        }
                        catch (Exception e)
                        {
                            // invalid input
                        }
                    }
                }


                Console.WriteLine();
            }

            Console.ReadLine();
        }