Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

A long version of my code golf attempt for http://stackoverflow.com/questions/2563561/code-golf-easter-spiral

View spiral_code_golf.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
num = ARGV[0].to_i
x = num
y = num - 2
 
grid = Array.new(y) { Array.new(x, '*')}
 
required_spiral_depth = x / 4 + 1
 
(1..required_spiral_depth*2).step(2) do |spiral_depth|
(spiral_depth..y-spiral_depth).each do |i|
grid[i][x-1-spiral_depth] = ' '
end
 
(spiral_depth..x-1-spiral_depth).each do |i|
grid[spiral_depth][i] = ' '
end
 
(spiral_depth..y-1-spiral_depth).each do |i|
grid[i][spiral_depth] = ' '
end
 
(spiral_depth..x-1-spiral_depth-2).each do |i|
grid[y-1-spiral_depth][i] = ' '
end
end
 
grid.each do |row|
print row
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.