Skip to content

Instantly share code, notes, and snippets.

@shyouhei
Created May 8, 2015 14:08
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/92e24733a122a6c7e67f to your computer and use it in GitHub Desktop.
Save shyouhei/92e24733a122a6c7e67f to your computer and use it in GitHub Desktop.
def Archimedean_spiral n
if n == 0
return [ [ '#' ] ]
else
inner = Archimedean_spiral(n - 1)
length = inner.size
ret = []
ret << ([ '#', '#' ] + ([ '#' ] * length) + [ '#', '#' ] )
ret << ([ '#', ' ' ] + ([ ' ' ] * length) + [ ' ', ' ' ] )
inner.each do |x|
line = [ '#', ' ' ] + x + [ '#', ' ' ]
ret << line
end
ret << ([ '#', ' ' ] + ([ ' ' ] * length) + [ '#', ' ' ] )
ret << ([ '#', '#' ] + ([ '#' ] * length) + [ '#', ' ' ] )
return ret
end
end
n = ARGV.first.to_i
spiral = Archimedean_spiral(n)
size = spiral.size
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