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

Stats:

CreatedAug 27, 2013
PublishedAug 28, 2013
Warriors Trained171000
Total Skips24709
Total Code Submissions531997
Total Times Completed80230
Ruby Completions2886
CoffeeScript Completions219
JavaScript Completions26057
Python Completions32031
Haskell Completions1121
Elixir Completions217
OCaml Completions73
PHP Completions1380
Scala Completions464
Java Completions6785
C++ Completions3783
C# Completions3896
NASM Completions15
C Completions1282
CFML Completions11
Crystal Completions25
Go Completions1084
Rust Completions873
Prolog Completions17
COBOL Completions12
Total Stars6416
% of votes with a positive feedback rating94% of 8495
Total "Very Satisfied" Votes7615
Total "Somewhat Satisfied" Votes754
Total "Not Satisfied" Votes126
Ad
Contributors
  • stevenbarragan Avatar
  • jhoffner Avatar
  • laoris Avatar
  • tko Avatar
  • awesson Avatar
  • firewatcher Avatar
  • 10XL Avatar
  • donaldsebleung Avatar
  • cacr Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • B1ts Avatar
  • Voile Avatar
  • KataSideKick Avatar
  • FArekkusu Avatar
  • bdw429s Avatar
  • _mer_ Avatar
  • monadius Avatar
  • hobovsky Avatar
  • uniapi Avatar
  • tonylicoding Avatar
  • username0 Avatar
  • user8436785 Avatar
  • Trambi Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • Glinator Avatar
  • KayleighWasTaken Avatar
Ad