Skip to content

Instantly share code, notes, and snippets.

@thinkerbot thinkerbot/spiral.rb
Last active Aug 29, 2015

Embed
What would you like to do?
x, y = 0, 0
xmin, xmax, ymin, ymax = 0, 0, 0, 0
e = Enumerator.new do |yy|
loop do
while x > xmin
yy << [x, y]
x -= 1
end
xmin -= 1
while y < ymax
yy << [x, y]
y += 1
end
ymax += 1
while x < xmax
yy << [x, y]
x += 1
end
xmax += 1
while y > ymin
yy << [x, y]
y -= 1
end
ymin -= 1
end
end
xmin, xmax, ymin, ymax = 1, 5, 1, 5
dx = 1
dy = 1
e = Enumerator.new do |yy|
x = xmin
y = ymin
while y <= ymax
while x <= xmax
yy << [x, y]
x += dx
end
x = xmin
y += dy
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.