01020304050607080910111213141516171819202122232425

Advent of Code

2019/2

1202 Program Alarm

in C#

by encse

On the way to your gravity assist around the Moon, your ship computer beeps angrily about a "1202 program alarm". On the radio, an Elf is already explaining how to handle the situation: "Don't worry, that's perfectly norma--" The ship computer bursts into flames.

You notify the Elves that the computer's magic smoke seems to have escaped. "That computer ran Intcode programs like the gravity assist program it was working on; surely there are enough spare parts up there to build a new Intcode computer!"

Read the full puzzle.

using System;

namespace AdventOfCode.Y2019.Day02;

[ProblemName("1202 Program Alarm")]
class Solution : Solver {

    public object PartOne(string input) => ExecIntCode(new IntCodeMachine(input), 12, 2);

    public object PartTwo(string input) {
        var icm = new IntCodeMachine(input);

        for (var sum = 0; ; sum++) {
            for (var verb = 0; verb <= sum; verb++) {
                var noun = sum - verb;
                var res = ExecIntCode(icm, noun, verb);
                if (res == 19690720) {
                    return 100 * noun + verb;
                }
            }
        }
        throw new Exception();
    }

    long ExecIntCode(IntCodeMachine icm, int noun, int verb) {
        icm.Reset();
        icm.memory[1] = noun;
        icm.memory[2] = verb;
        icm.Run();
        return icm.memory[0];
    }
}

Please ☆ my repo if you like it!

© 2025 Advent of Code is a registered trademark in the US Images provided by Bing image creator