Example #1
0
        override public void part1()
        {
            Dictionary <string, long> board    = new Dictionary <string, long>();
            IntcodeComputer           computer = new IntcodeComputer();

            computer.loadProgramInput(13);
            computer.createProgramFromInput();
            while (!computer.hasStopped)
            {
                long x      = computer.executeProgram(null, RunMode.BREAK_ON_OUTPUT);
                long y      = computer.executeProgram(null, RunMode.BREAK_ON_OUTPUT);
                long tileId = computer.executeProgram(null, RunMode.BREAK_ON_OUTPUT);
                tileId = computer.getDiagnosticCode();
                if (!board.ContainsKey(x.ToString() + ',' + y.ToString()))
                {
                    board.Add(x.ToString() + ',' + y.ToString(), tileId);
                }
                else
                {
                    board[x.ToString() + ',' + y.ToString()] = tileId;
                }
            }
            int result = 0;

            foreach (int i in board.Values)
            {
                if (i == 2)
                {
                    result++;
                }
            }
            System.Console.WriteLine("Day 13. Solution1:" + result.ToString());
        }
Example #2
0
        override public void part2()
        {
            Dictionary <string, long> board    = new Dictionary <string, long>();
            IntcodeComputer           computer = new IntcodeComputer();

            computer.loadProgramInput(13);
            computer.createProgramFromInput();
            computer.saveInputAtPosition(0, 2);
            List <int> input   = new List <int>();
            long       paddleX = -1;
            long       ballX   = -1;
            long       score   = 0;

            while (!computer.hasStopped)
            {
                int joystick = 0;
                if (ballX > paddleX && ballX >= 0 && paddleX >= 0)
                {
                    joystick = 1;
                }
                if (ballX < paddleX && ballX >= 0 && paddleX >= 0)
                {
                    joystick = -1;
                }
                input.Add(joystick);
                long x      = computer.executeProgram(input, RunMode.BREAK_ON_OUTPUT);
                long y      = computer.executeProgram(null, RunMode.BREAK_ON_OUTPUT);
                long tileId = computer.executeProgram(null, RunMode.BREAK_ON_OUTPUT);
                if (!board.ContainsKey(x.ToString() + ',' + y.ToString()))
                {
                    board.Add(x.ToString() + ',' + y.ToString(), tileId);
                }
                else
                {
                    board[x.ToString() + ',' + y.ToString()] = tileId;
                }
                if (x == -1 && y == 0)
                {
                    score = tileId;
                }
                if (tileId == 3)
                {
                    paddleX = x;
                }
                if (tileId == 4)
                {
                    ballX = x;
                }
                input = new List <int> {
                    0
                };
            }
            System.Console.WriteLine("Day 13. Solution2:" + score.ToString());
        }
Example #3
0
 private void doPainting()
 {
     while (!computer.hasStopped)
     {
         input.Add(getInput());
         computer.executeProgram(input, RunMode.BREAK_ON_OUTPUT);
         paintVisitedPanel(computer.getDiagnosticCode());
         computer.executeProgram(input, RunMode.BREAK_ON_OUTPUT);
         changeDirection(computer.getDiagnosticCode());
         changePosition();
         input = new List <int> {
             0
         };
     }
 }
Example #4
0
        override public void part1()
        {
            List <string> numberPermutations = StringUtils.permute("01234", 0, 4);
            int           result             = 0;

            foreach (string perm in numberPermutations)
            {
                int        local  = 0;
                List <int> phases = createPhases(perm);
                for (int i = 0; i < 5; i++)
                {
                    IntcodeComputer computer = new IntcodeComputer();
                    computer.loadProgramInput(7);
                    computer.createProgramFromInput();
                    computer.executeProgram(new List <int> {
                        phases[i], local
                    });
                    local = (int)computer.getDiagnosticCode();
                }
                if (local > result)
                {
                    result = local;
                }
            }
            System.Console.WriteLine("Day 7. Solution1 Expected:277328");
            System.Console.WriteLine("Day 7. Solution1:" + result.ToString());
        }
Example #5
0
        override public void part1()
        {
            IntcodeComputer computer = new IntcodeComputer();

            computer.loadProgramInput(2);
            computer.createProgramFromInput();
            computer.executeProgram(12, 2);
            System.Console.WriteLine("Day 2. Solution1 expected: 3716293");
            System.Console.WriteLine("Day 2. Solution1:" + computer.getComputerOutput(0).ToString());
        }
Example #6
0
        override public void part1()
        {
            IntcodeComputer computer = new IntcodeComputer();
            List <int>      l        = new List <int>();

            l.Add(1);
            computer.loadProgramInput(5);
            computer.createProgramFromInput();
            computer.executeProgram(l);
            System.Console.WriteLine("Day 5. Solution1 expected: 12234644");
            System.Console.WriteLine("Day 5. Solution1:" + computer.getDiagnosticCode().ToString());
        }
Example #7
0
        override public void part1()
        {
            IntcodeComputer computer = new IntcodeComputer();

            computer.loadProgramInput(9);
            computer.createProgramFromInput();
            computer.executeProgram(new List <int> {
                1
            });
            long local = computer.getDiagnosticCode();

            System.Console.WriteLine("Day 9. Solution1:" + local.ToString());
        }
Example #8
0
        override public void part2()
        {
            IntcodeComputer computer = new IntcodeComputer();

            computer.loadProgramInput(2);
            for (int noun = 0; noun < 100; noun++)
            {
                for (int verb = 0; verb < 100; verb++)
                {
                    computer.createProgramFromInput();
                    computer.executeProgram(noun, verb);
                    if (computer.getComputerOutput(0) == 19690720)
                    {
                        System.Console.WriteLine("Day 2. Solution2 expected: 6429");
                        System.Console.WriteLine("Day 2. Solution2:" + (100 * noun + verb).ToString());
                        break;
                    }
                }
            }
        }