Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaszkorecki/353155 to your computer and use it in GitHub Desktop.
Save lukaszkorecki/353155 to your computer and use it in GitHub Desktop.
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