Skip to content

Instantly share code, notes, and snippets.

@shyouhei
Created May 9, 2015 02:43
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 shyouhei/2fa3007be1c02fabe54c to your computer and use it in GitHub Desktop.
Save shyouhei/2fa3007be1c02fabe54c to your computer and use it in GitHub Desktop.
n = ARGV.first.to_i
size = n * 4 + 1
spiral = Array.new(size) { Array.new(size) { ' ' } }
def Archimedean_spiral_sequence(n)
if n == 0
yield 0, 0
else
Archimedean_spiral_sequence(n - 1) do |x, y|
yield x + 2, y + 2
end
2.upto(n * 4)do |x|
yield x, n * 4 - 1
end
(n * 4 - 1).downto(0) do |y|
yield n * 4, y
end
(n * 4).downto(0) do |x|
yield x, 0
end
0.upto(n * 4) do |y|
yield 0, y
end
end
end
Archimedean_spiral_sequence(n) do |x, y|
spiral[x][y] = '#'
end
spiral.each_with_index do |line1, i|
line2 = spiral[size - i - 1]
string = (line1 + [ '#' ] + line2.reverse).join('')
puts string
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment