Created
April 2, 2010 13:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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