4 kyu
Snail
25,960 of 79,931stevenbarragan
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 | 170515 |
Total Skips | 24660 |
Total Code Submissions | 530904 |
Total Times Completed | 79931 |
Ruby Completions | 2883 |
CoffeeScript Completions | 219 |
JavaScript Completions | 25960 |
Python Completions | 31922 |
Haskell Completions | 1120 |
Elixir Completions | 217 |
OCaml Completions | 73 |
PHP Completions | 1374 |
Scala Completions | 464 |
Java Completions | 6758 |
C++ Completions | 3760 |
C# Completions | 3873 |
NASM Completions | 15 |
C Completions | 1278 |
CFML Completions | 11 |
Crystal Completions | 24 |
Go Completions | 1076 |
Rust Completions | 869 |
Prolog Completions | 17 |
COBOL Completions | 12 |
Total Stars | 6404 |
% of votes with a positive feedback rating | 94% of 8482 |
Total "Very Satisfied" Votes | 7605 |
Total "Somewhat Satisfied" Votes | 751 |
Total "Not Satisfied" Votes | 126 |