Skip to content

@veryhappythings /spiral_code_golf.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.