Skip to content

Instantly share code, notes, and snippets.

@BelegCuthalion
Created September 1, 2021 12:53
Show Gist options
  • Select an option

  • Save BelegCuthalion/aa45d25076e5751ac60cec275abe08c6 to your computer and use it in GitHub Desktop.

Select an option

Save BelegCuthalion/aa45d25076e5751ac60cec275abe08c6 to your computer and use it in GitHub Desktop.
def snail(snail_map):
s = snail_map
n = len(s)
l = []
if n > 1:
for i in range(n):
l.append(s[0][i])
for i in range(1, n-1):
l.append(s[i][n-1])
for i in range(n-1, -1, -1):
l.append(s[n-1][i])
for i in range(n-2, 0, -1):
l.append(s[i][0])
s = [s[i][1:n-1] for i in range(n) if i != 0 and i != n-1]
return l + snail(s)
elif n == 1:
if len(s[0]) > 0:
return [s[0][0]]
else: # This happens only in the case that s = [[]]
return []
else: # n == 0
return l # l = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment