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

Stats:

CreatedAug 27, 2013
PublishedAug 28, 2013
Warriors Trained170515
Total Skips24660
Total Code Submissions530904
Total Times Completed79931
Ruby Completions2883
CoffeeScript Completions219
JavaScript Completions25960
Python Completions31922
Haskell Completions1120
Elixir Completions217
OCaml Completions73
PHP Completions1374
Scala Completions464
Java Completions6758
C++ Completions3760
C# Completions3873
NASM Completions15
C Completions1278
CFML Completions11
Crystal Completions24
Go Completions1076
Rust Completions869
Prolog Completions17
COBOL Completions12
Total Stars6404
% of votes with a positive feedback rating94% of 8482
Total "Very Satisfied" Votes7605
Total "Somewhat Satisfied" Votes751
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