Created
November 16, 2016 10:50
-
-
Save mvallebr/0494a84d1e69142ef6acdf3d1b2ff8c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def snail(array): | |
| return list(array[0]) + snail(zip(*array[1:])[::-1]) if array else [] | |
| # Tests | |
| array = [[]] | |
| expected = [] | |
| test.assert_equals(snail(array), expected) | |
| array = [[1,2,3], | |
| [4,5,6], | |
| [7,8,9]] | |
| expected = [1,2,3,6,9,8,7,4,5] | |
| test.assert_equals(snail(array), expected) | |
| array = [[1,2,3], | |
| [8,9,4], | |
| [7,6,5]] | |
| expected = [1,2,3,4,5,6,7,8,9] | |
| test.assert_equals(snail(array), expected) | |
| array = [[1,2,3,4], | |
| [5,6,7,8], | |
| [9,10,11,12], | |
| [13,14,15,16]] | |
| expected = [1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10] | |
| test.assert_equals(snail(array), expected) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment