static private long RunSpringScript() { bool halt = false; long output = -123; while (!halt) { halt = false; bool hasOutput = false; long result = sProgram.GetNextOutput(ref halt, ref hasOutput); if ((result >= 10) && (result < 255)) { char c = (char)result; Console.Write(c); } if (hasOutput) { output = result; } } return(output); }
static int FindSantaSquare() { bool halt = false; bool hasOutput = false; InitMap(); var inputs = new long[2]; int xLeft = 0; int xRight = -1; for (int y = 0; y < sMapSize; ++y) { bool beamStarted = false; int beamStartX = -1; int beamEndX = -1; for (int x = xLeft; x < sMapSize; ++x) { long result; inputs[0] = x; inputs[1] = y; sProgram.Reset(); sProgram.SetInputData(inputs); result = sProgram.GetNextOutput(ref halt, ref hasOutput); if (result == 1) { if (!beamStarted) { sLeftEdge[y] = x; beamStartX = x; xLeft = x - 2; if (xLeft < 0) { xLeft = 0; } x = xRight; if (x < beamStartX) { x = beamStartX; } } beamStarted = true; } else if (beamStarted && (result == 0)) { sRightEdge[y] = x; beamEndX = x; for (int i = beamStartX; i < beamEndX; ++i) { sMap[i, y] = '#'; } xRight = x - 1; if (xRight < 0) { xRight = 0; } break; } } if ((beamEndX - beamStartX) >= 100) { if (y >= 100) { Console.WriteLine($"[{y}] {beamStartX} -> {beamEndX}"); int rightTopEdge = sRightEdge[y - 99]; int leftBottomEdge = sLeftEdge[y]; if ((leftBottomEdge + 99) < rightTopEdge) { return(y); } } } } return(-1); }