3 kyu

Make a spiral

6,780 of 15,227Bugari

Description:

Your task, is to create a NxN spiral with a given size.

For example, spiral with size 5 should look like this:

00000
....0
000.0
0...0
00000

and with the size 10:

0000000000
.........0
00000000.0
0......0.0
0.0000.0.0
0.0..0.0.0
0.0....0.0
0.000000.0
0........0
0000000000

Return value should contain array of arrays, of 0 and 1, with the first row being composed of 1s. For example for given size 5 result should be:

[[1,1,1,1,1],[0,0,0,0,1],[1,1,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]
{{1,1,1,1,1},{0,0,0,0,1},{1,1,1,0,1},{1,0,0,0,1},{1,1,1,1,1}}
[[1,1,1,1,1],[0,0,0,0,1],[1,1,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]
[1 1 1 1 1; 0 0 0 0 1; 1 1 1 0 1; 1 0 0 0 1; 1 1 1 1 1]
[[1,1,1,1,1],[0,0,0,0,1],[1,1,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]

Because of the edge-cases for tiny spirals, the size will be at least 5.

General rule-of-a-thumb is, that the snake made with '1' cannot touch to itself.

Algorithms
Arrays
Logic

More By Author:

Check out these other kata created by Bugari

Stats:

CreatedApr 16, 2014
PublishedApr 16, 2014
Warriors Trained44667
Total Skips10290
Total Code Submissions98680
Total Times Completed15227
CoffeeScript Completions60
JavaScript Completions4080
Python Completions6780
Ruby Completions437
Haskell Completions310
Swift Completions190
Java Completions1663
Julia Completions37
Rust Completions397
C# Completions867
COBOL Completions6
C Completions478
Go Completions229
Kotlin Completions104
Lua Completions62
D Completions8
Total Stars1790
% of votes with a positive feedback rating91% of 1935
Total "Very Satisfied" Votes1662
Total "Somewhat Satisfied" Votes212
Total "Not Satisfied" Votes61
Ad
Contributors
  • Bugari Avatar
  • jhoffner Avatar
  • xcthulhu Avatar
  • user9935269 Avatar
  • asmgf Avatar
  • GiacomoSorbi Avatar
  • Osmosis Avatar
  • JDeBolt Avatar
  • michalmela Avatar
  • Chrono79 Avatar
  • docgunthrop Avatar
  • Davo36 Avatar
  • Voile Avatar
  • Avanta Avatar
  • cvb4114 Avatar
  • hobovsky Avatar
  • xfix Avatar
  • stellartux Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • dfhwze Avatar
  • ewelborn Avatar
  • saudiGuy Avatar
Ad