Exemplo n.º 1
0
        public PaintingRobot(string sProgram, long start)
        {
            direction       = General.Direction.Up;
            CurrentPosition = new General.clsPoint(0, 0);
            paintedPanels   = new Dictionary <General.clsPoint, long>();
            paintedPanels[CurrentPosition] = start;
            computer = new IntcodeComputer();
            computer.loadProgram(sProgram);

            while (!computer.Halted)
            {
                Move();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The second puzzle.
        /// </summary>
        /// <param name="input">The AOCInput object for getting the input.</param>
        /// <returns>The answer.</returns>
        public override object Puzzle2(AOCInput input)
        {
            int[] program = input.GetInput(",").Select(x => int.Parse(x)).ToArray();

            for (int noun = 0; noun < 99; ++noun)
            {
                for (int verb = 0; verb < 99; ++verb)
                {
                    program[1] = noun;
                    program[2] = verb;

                    IntcodeComputer computer = new IntcodeComputer((int[])program.Clone());
                    int             output   = computer.Run();

                    if (output == 19690720)
                    {
                        return(100 * noun + verb);
                    }
                }
            }

            return("Program failed!");
        }
Exemplo n.º 3
0
 private long Amplifier(IntcodeComputer computer, long input)
 {
     computer.InputValue(input);
     computer.ExecuteProgram();
     return(computer.ReadOutputs().Last());
 }