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

Stats:

CreatedAug 27, 2013
PublishedAug 28, 2013
Warriors Trained169940
Total Skips24609
Total Code Submissions529927
Total Times Completed79658
Ruby Completions2879
CoffeeScript Completions219
JavaScript Completions25882
Python Completions31794
Haskell Completions1120
Elixir Completions216
OCaml Completions73
PHP Completions1370
Scala Completions464
Java Completions6738
C++ Completions3740
C# Completions3861
NASM Completions15
C Completions1273
CFML Completions11
Crystal Completions24
Go Completions1070
Rust Completions865
Prolog Completions17
COBOL Completions12
Total Stars6390
% of votes with a positive feedback rating94% of 8466
Total "Very Satisfied" Votes7593
Total "Somewhat Satisfied" Votes748
Total "Not Satisfied" Votes125
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