3 kyu

Make a spiral

1,665 of 15,266Bugari

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 Trained44757
Total Skips10306
Total Code Submissions98833
Total Times Completed15266
CoffeeScript Completions60
JavaScript Completions4088
Python Completions6799
Ruby Completions437
Haskell Completions313
Swift Completions190
Java Completions1665
Julia Completions37
Rust Completions398
C# Completions869
COBOL Completions6
C Completions479
Go Completions230
Kotlin Completions105
Lua Completions63
D Completions8
Total Stars1795
% of votes with a positive feedback rating91% of 1941
Total "Very Satisfied" Votes1667
Total "Somewhat Satisfied" Votes213
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