4 kyu
Snail
219 of 79,658stevenbarragan
Description:
Snail Sort
Given an n x n
array, return the array elements arranged from outermost elements to the middle element, traveling clockwise.
array = [[1,2,3],
[4,5,6],
[7,8,9]]
snail(array) #=> [1,2,3,6,9,8,7,4,5]
For better understanding, please follow the numbers of the next array consecutively:
array = [[1,2,3],
[8,9,4],
[7,6,5]]
snail(array) #=> [1,2,3,4,5,6,7,8,9]
This image will illustrate things more clearly:
NOTE: The idea is not sort the elements from the lowest value to the highest; the idea is to traverse the 2-d array in a clockwise snailshell pattern.
NOTE 2: The 0x0 (empty matrix) is represented as en empty array inside an array [[]]
.
Arrays
Algorithms
Similar Kata:
Stats:
Created | Aug 27, 2013 |
Published | Aug 28, 2013 |
Warriors Trained | 169940 |
Total Skips | 24609 |
Total Code Submissions | 529927 |
Total Times Completed | 79658 |
Ruby Completions | 2879 |
CoffeeScript Completions | 219 |
JavaScript Completions | 25882 |
Python Completions | 31794 |
Haskell Completions | 1120 |
Elixir Completions | 216 |
OCaml Completions | 73 |
PHP Completions | 1370 |
Scala Completions | 464 |
Java Completions | 6738 |
C++ Completions | 3740 |
C# Completions | 3861 |
NASM Completions | 15 |
C Completions | 1273 |
CFML Completions | 11 |
Crystal Completions | 24 |
Go Completions | 1070 |
Rust Completions | 865 |
Prolog Completions | 17 |
COBOL Completions | 12 |
Total Stars | 6390 |
% of votes with a positive feedback rating | 94% of 8466 |
Total "Very Satisfied" Votes | 7593 |
Total "Somewhat Satisfied" Votes | 748 |
Total "Not Satisfied" Votes | 125 |