void dfs(long input, HashSet <int> prev, long[] memory) { if (prev.Count == 5) { max = input > max ? input : max; return; } for (int i = 0; i < 5; i++) { if (!prev.Contains(i)) { long output; IntComputer intComputer = new IntComputer(memory); bool halt = intComputer.GetDiagnosticCode(new List <long>() { i, input }, out output); HashSet <int> next = new HashSet <int>(prev); next.Add(i); dfs(output, next, memory); } } }
public static void GetBoostKeycode(int testInput) { long[] memory = ParseInput(); IntComputer intComputer = new IntComputer(memory); long output; while (intComputer.isRunning) { intComputer.GetDiagnosticCode(new List <long>() { testInput }, out output); Console.WriteLine("OUTPUT: " + output); } }
void solve2(long[] memory, List <int> phases) { IntComputer[] programs = new IntComputer[5]; for (int i = 0; i < 5; i++) { programs[i] = new IntComputer((long[])memory.Clone()); } bool firstPass = true; long input = 0; for (int j = 0; j < 5; j = (j + 1) % 5) { IntComputer program = programs[j]; int n = phases[j]; List <long> inputs = new List <long>(); if (firstPass) { inputs.Add(n); } if (firstPass && j == 4) { firstPass = false; } inputs.Add(input); program.GetDiagnosticCode(inputs, out input); if (!program.isRunning && j == 4) { max = Math.Max(max, input); return; } } }