private IEnumerable <(int, int)> GetBounds( int maxX = int.MaxValue, int maxY = int.MaxValue, int startY = 0) { int prevWidth = 0; int startX = 0; for (int y = startY; y < maxY; y++) { bool isFoundFirst = false; int first = -1; bool isReturnedAnswer = false; for (int x = startX; x < maxX; x++) { var ic = new Intcode(_program); ic.AddInputs(x, y); var output = (int)ic.Execute().First(); if (!isFoundFirst && output == 1) { isFoundFirst = true; first = x; startX = x; if (prevWidth > 0) { x += prevWidth - 1; } } else if (!isFoundFirst && x - startX > 10) { prevWidth = 0; yield return(-1, -1); isReturnedAnswer = true; break; } else if (isFoundFirst && output == 0) { prevWidth = x - first - 1; yield return(first, x - 1); isReturnedAnswer = true; break; } } if (!isReturnedAnswer) { if (first == -1) { prevWidth = 0; yield return(-1, -1); } else { prevWidth = maxX - first - 1; yield return(first, maxX - 1); } } } }
public long Run(int input) { var intcode = new Intcode(_program); intcode.AddInputs(input); return(intcode.Execute().First()); }
public long DoCalc(int input) { var intcode = new Intcode(_program); intcode.AddInputs(input); return(intcode.Execute().Last()); }
public long Execute(int noun, int verb) { // This was based on an older version of the Intcode machine. There were no // I/O opcodes - it was based on direct reads/writes into memory long[] memory = new long[_programData.Length]; Array.Copy(_programData, memory, _programData.Length); var intcode = new Intcode(memory); intcode.Poke(1, noun); intcode.Poke(2, verb); // Run to termination intcode.Execute().LastOrDefault(); return(intcode.Peek(0)); }
public int BlockCountExit() { var intcode = new Intcode(_program); var screen = new Dictionary <(long, long), long>(); using (var enumer = intcode.Execute().GetEnumerator()) { while (enumer.MoveNext()) { var x = enumer.Current; enumer.MoveNext(); var y = enumer.Current; enumer.MoveNext(); var tile = enumer.Current; screen[(x, y)] = tile;