private static void Part1() { var sw = System.Diagnostics.Stopwatch.StartNew(); var ram = new long[rom.Count]; rom.CopyTo(ram, 0); ram[1] = 12; ram[2] = 2; IntcodeComputer computer = new IntcodeComputer(ram); long output = computer.Run(); System.Diagnostics.Debug.WriteLine($"Part 1: {output}"); sw.Stop(); System.Diagnostics.Debug.WriteLine(sw.Elapsed); }
public static int Run(IEnumerable <int> initialPositions) { var computer = new IntcodeComputer(initialPositions); for (var noun = 0; noun < 100; noun++) { for (var verb = 0; verb < 100; verb++) { computer.SetInitialNounAndVerb(noun, verb); computer.Run(); if (computer.PeekResult() == 19690720) { return(100 * noun + verb); } computer.Reset(); } } throw new IndexOutOfRangeException("ran out of nouns and verbs to try"); }
private static void Part2() { var sw = System.Diagnostics.Stopwatch.StartNew(); var ram = new long[rom.Count]; for (int i = 0; i < 99; i++) { for (int j = 0; j < 99; j++) { rom.CopyTo(ram, 0); ram[1] = i; ram[2] = j; IntcodeComputer computer = new IntcodeComputer(ram); long output = computer.Run(); if (output == 19690720) { System.Diagnostics.Debug.WriteLine($"Part 2: {100 * i + j}"); sw.Stop(); System.Diagnostics.Debug.WriteLine(sw.Elapsed); return; } } } }