3 kyu

Make a spiral

59 of 15,031Bugari

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

Similar Kata:

More By Author:

Check out these other kata created by Bugari

Stats:

CreatedApr 16, 2014
PublishedApr 16, 2014
Warriors Trained44095
Total Skips10212
Total Code Submissions97885
Total Times Completed15031
CoffeeScript Completions59
JavaScript Completions4048
Python Completions6691
Ruby Completions430
Haskell Completions305
Swift Completions187
Java Completions1636
Julia Completions36
Rust Completions388
C# Completions856
COBOL Completions6
C Completions467
Go Completions219
Kotlin Completions100
Lua Completions59
D Completions7
Total Stars1776
% of votes with a positive feedback rating91% of 1919
Total "Very Satisfied" Votes1647
Total "Somewhat Satisfied" Votes212
Total "Not Satisfied" Votes60
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