Open the context
Choose the project folder and name the files or behavior involved.
Visit every coordinate of a rectangular grid in a clockwise spiral starting at the top left. Check zero dimensions and single rows or columns, rejecting dimensions outside zero through 100 and proving each coordinate appears once.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def spiral(rows, columns):
if any(type(v) is not int or not 0 <= v <= 100
for v in (rows, columns)):
raise ValueError("dimension.range")
top, bottom, left, right = 0, rows - 1, 0, columns - 1
result = []
while top <= bottom and left <= right:
result.extend((top, c) for c in range(left, right + 1))
top += 1
result.extend((r, right) for r in range(top, bottom + 1))
right -= 1
if top <= bottom:
result.extend((bottom, c) for c in range(right, left - 1, -1))
bottom -= 1
if left <= right:
result.extend((r, left) for r in range(bottom, top - 1, -1))
left += 1
return resultThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.