5 kyu

The Clockwise Spiral

995 of 3,935alex.budiakov

Description:

Do you know how to make a spiral? Let's test it!


Classic definition: A spiral is a curve which emanates from a central point, getting progressively farther away as it revolves around the point.


Your objective is to complete a function createSpiral(N) that receives an integer N and returns an NxN two-dimensional array with numbers 1 through NxN represented as a clockwise spiral.

Return an empty array if N < 1 or N is not int / number

Examples:

N = 3 Output: [[1,2,3],[8,9,4],[7,6,5]]

1    2    3    
8    9    4    
7    6    5    

N = 4 Output: [[1,2,3,4],[12,13,14,5],[11,16,15,6],[10,9,8,7]]

1   2   3   4
12  13  14  5
11  16  15  6
10  9   8   7

N = 5 Output: [[1,2,3,4,5],[16,17,18,19,6],[15,24,25,20,7],[14,23,22,21,8],[13,12,11,10,9]]

1   2   3   4   5    
16  17  18  19  6    
15  24  25  20  7    
14  23  22  21  8    
13  12  11  10  9
Arrays
Puzzles

Similar Kata:

More By Author:

Check out these other kata created by alex.budiakov

Stats:

CreatedMay 7, 2014
PublishedMay 7, 2014
Warriors Trained12172
Total Skips2356
Total Code Submissions28996
Total Times Completed3935
JavaScript Completions995
CoffeeScript Completions10
Java Completions955
Python Completions956
C# Completions248
Go Completions284
Haskell Completions31
C++ Completions395
Elixir Completions34
COBOL Completions4
C Completions122
D Completions4
Total Stars364
% of votes with a positive feedback rating91% of 599
Total "Very Satisfied" Votes505
Total "Somewhat Satisfied" Votes77
Total "Not Satisfied" Votes17
Ad
Contributors
  • alex.budiakov Avatar
  • smile67 Avatar
  • mdsmithson Avatar
  • siebenschlaefer Avatar
  • docgunthrop Avatar
  • JohanWiltink Avatar
  • Blind4Basics Avatar
  • KataSideKick Avatar
  • natehart Avatar
  • FArekkusu Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • akar-0 Avatar
Ad