/// <summary> /// The first puzzle. /// </summary> /// <param name="input">The AOCInput object for getting the input.</param> /// <returns>The answer.</returns> public override object Puzzle1(AOCInput input) { int[] software = input.GetInput(",").Select(x => int.Parse(x)).ToArray(); IntcodeComputer computer; int[] sequence = new int[] { 0, 1, 2, 3, 4 }; var permutations = GetPermutations <int>(sequence, 5); long maxOutput = 0; int maxSequence = 0; for (int i = 0; i < permutations.Count(); ++i) { long output = 0; for (int j = 0; j < 5; ++j) { computer = new IntcodeComputer((long[])software.Clone(), false); computer.Run(permutations.ElementAt(i).ElementAt(j), output); output = computer.Outputs.Last(); } if (output > maxOutput) { maxOutput = output; maxSequence = i; } } return(maxOutput); }
/// <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) { long[] program = input.GetInput(",").Select(x => long.Parse(x)).ToArray(); IntcodeComputer computer = new IntcodeComputer(program); computer.Run(5); return computer.Outputs[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) { long[] software = input.GetInput(",").Select(x => long.Parse(x)).ToArray(); IntcodeComputer computer = new IntcodeComputer(software, false); computer.Run(2); return(computer.Outputs.Last()); }
/// <summary> /// The first puzzle. /// </summary> /// <param name="input">The AOCInput object for getting the input.</param> /// <returns>The answer.</returns> public override object Puzzle1(AOCInput input) { int[] program = input.GetInput(",").Select(x => int.Parse(x)).ToArray(); program[1] = 12; program[2] = 2; IntcodeComputer computer = new IntcodeComputer(program); return(computer.Run()); }
/// <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!"); }