Tricky! Not sure I found the most efficient way to do it - but it works, and I think it's relatively clean(ish) :)
Watch me solve it too: youtu.be/h-OzkY1_8mU
const snail = array => { const middle = array.slice(1, array.length - 1).map(row => row.slice(1, row.length - 1) ) return [ array[0], array.slice(1, array.length - 1).map(row => row[row.length - 1] ), array.length > 1 ? array[array.length - 1].reverse() : [], array.slice(1, array.length - 1).reverse().map(row => row[0] ), middle.length > 0 ? snail(middle) : [] ].flat() }
Hey Chris, I made a replica of your solution translated to Python3.5 or greater.
from itertools import chain def snail(arr): mid = list(map(lambda row : row[slice(1, len(row)-1)], arr[slice(1,len(arr)-1)])) return list(chain.from_iterable([ arr[0], list(map(lambda row: row[len(row)-1], arr[slice(1,len(arr)-1)])), list(reversed(arr[len(arr)-1])) if len(arr) > 1 else [], list(map(lambda row: row[0],list(reversed(arr[slice(1,len(arr)-1)])))), snail(mid) if len(mid) > 0 else [] ]))if len(arr) >= 1 else [[]]
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Tricky! Not sure I found the most efficient way to do it - but it works, and I think it's relatively clean(ish) :)
Watch me solve it too: youtu.be/h-OzkY1_8mU
Hey Chris, I made a replica of your solution translated to Python3.5 or greater.