Skip to content

Instantly share code, notes, and snippets.

@stevenbarragan
Created December 1, 2017 19:00
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 stevenbarragan/1fda98ccd29d9e74cf27b4f1092bdd0d to your computer and use it in GitHub Desktop.
Save stevenbarragan/1fda98ccd29d9e74cf27b4f1092bdd0d to your computer and use it in GitHub Desktop.
# https://www.codewars.com/kata/snail
def snail(matriz)
result = []
step = 0
while matriz.size > 0
step = 0 if step > 3
case step
when 0
result += matriz.shift
when 1
result += matriz.map{ |x| x.pop }
when 2
result += matriz.pop.reverse
when 3
result += matriz.map{ |x| x.shift }.reverse
end
step += 1
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment