4 kyu
Snail
32,031 of 80,230stevenbarragan
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 | 171000 |
Total Skips | 24709 |
Total Code Submissions | 531997 |
Total Times Completed | 80230 |
Ruby Completions | 2886 |
CoffeeScript Completions | 219 |
JavaScript Completions | 26057 |
Python Completions | 32031 |
Haskell Completions | 1121 |
Elixir Completions | 217 |
OCaml Completions | 73 |
PHP Completions | 1380 |
Scala Completions | 464 |
Java Completions | 6785 |
C++ Completions | 3783 |
C# Completions | 3896 |
NASM Completions | 15 |
C Completions | 1282 |
CFML Completions | 11 |
Crystal Completions | 25 |
Go Completions | 1084 |
Rust Completions | 873 |
Prolog Completions | 17 |
COBOL Completions | 12 |
Total Stars | 6416 |
% of votes with a positive feedback rating | 94% of 8495 |
Total "Very Satisfied" Votes | 7615 |
Total "Somewhat Satisfied" Votes | 754 |
Total "Not Satisfied" Votes | 126 |