Skip to content

Instantly share code, notes, and snippets.

@veryhappythings
Created April 2, 2010 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save veryhappythings/353151 to your computer and use it in GitHub Desktop.
Save veryhappythings/353151 to your computer and use it in GitHub Desktop.
A long version of my code golf attempt for http://stackoverflow.com/questions/2563561/code-golf-easter-spiral
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