Created
December 1, 2017 19:00
-
-
Save stevenbarragan/1fda98ccd29d9e74cf27b4f1092bdd0d to your computer and use it in GitHub Desktop.
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
# 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