예제 #1
0
        private static void Part1(string[] args)
        {
            Console.WriteLine("   Part 1");
            String[] lines = File.ReadAllLines(Part1Input);
            Console.WriteLine("\tRead {0} inputs", lines.Length);

            (String s, int i)instruct;

            String[] prog  = new String[lines.Length];
            int[]    iargs = new int[lines.Length];


            for (int i = 0; i < lines.Length; i++)
            {
                instruct = IntCode08.parseInstruction(lines[i]);
                prog[i]  = instruct.s;
                iargs[i] = instruct.i;
            }

            IntCode08 machine = new IntCode08(prog, iargs);

            // Console.Write(machine);

            int count = machine.RunUntilLoop();

            Console.WriteLine($"\n\tPart 1 Solution: {count}");
        }
예제 #2
0
        private static void Part2(string[] args)
        {
            Console.WriteLine("   Part 2");
            String[] lines = File.ReadAllLines(Part2Input);
            Console.WriteLine("\tRead {0} inputs", lines.Length);


            (String s, int i)instruct;

            String[] prog  = new String[lines.Length];
            int[]    iargs = new int[lines.Length];


            for (int i = 0; i < lines.Length; i++)
            {
                instruct = IntCode08.parseInstruction(lines[i]);
                prog[i]  = instruct.s;
                iargs[i] = instruct.i;
            }

            IntCode08 machine = new IntCode08(prog, iargs);

            // Console.Write(machine);


            /*
             *
             *     INSIGHT
             *     Assume that for all swap, the program only ever does two things: loop or terminate
             *     If an instruction is encountered twice (the pc repeats) a loop has started.
             *
             */

            machine.FindFlip();


            int last_accum = machine.last_accum;


            Console.WriteLine($"\n\tPart 2 Solution: {last_accum}");
        }