Exemple #1
0
    public void Solve(ReadOnlySpan <byte> input, Solution solution)
    {
        ReadOnlySpan <int> intCode = IntCode.ParseFromInput(input);

        int[] memory = intCode.ToArray();

        int part1 = Run(memory, 12, 2);

        solution.SubmitPart1(part1);

        for (int noun = 0; noun < 100; noun++)
        {
            for (int verb = 0; verb < 100; verb++)
            {
                // reinitialise memory to intcode
                intCode.CopyTo(memory);

                if (Run(memory, noun, verb) == 19690720)
                {
                    int part2 = 100 * noun + verb;
                    solution.SubmitPart2(part2);
                    return;
                }
            }
        }

        ThrowHelper.ThrowException("Unable to find solution for part 2");
    }