+ 57

# *FRIDAY CHALLENGE* : write a code that gets as input a positive number N > 1 and prints a N x N CLOCKWISE-SPIRAL-SQUARE

Example: if N=3 then the Clockwise Spiral Square looks like this: 1 2 3 8 9 4 7 6 5 if N=5 then the Clockwise Spiral Square looks like this: 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 (In this example the columns don't align perfectly, but in the output of your code the columns should left-align) -Start at top left with 1. -numbers increase by 1 until N*N -flow of increasing numbers spirals inward maintaining the square shape HAV

18th Aug 2017, 12:59 AM
Louis
18th Aug 2017, 4:11 AM
Krishna Teja Yeluripati
+ 23
here is mine.... check it out.. input the size... eg: 6 CHECKING FOR VALID INPUT IS INCLUDED.. https://code.sololearn.com/cNCzt3qU6XTs/?ref=app
18th Aug 2017, 3:46 AM
sayan chandra
19th Oct 2017, 8:16 AM
Corey
+ 15
Here is mine. Checks for valid numerical input and prints the spiral so that everything lines up together. https://code.sololearn.com/cz0NxfCe75uW/?ref=app
18th Aug 2017, 3:22 AM
Vari93
+ 14
@Michal, my code is higher up in this thread.
31st Aug 2017, 6:54 PM
Louis
+ 13
Ok. The response was fantastic. Here is my version. It is definately not the best. All recursion. https://code.sololearn.com/cV19qNIOpb7T/?ref=app It is too difficult to pick a winner. I think everyone had fun and the warm feeling you get from accomplishing the task is enough. Congrats to all.
19th Aug 2017, 6:08 AM
Louis
+ 12
@Vari93 and sayan. WOW that was quick, precise and clever. Well done. It took me much longer.
18th Aug 2017, 4:04 AM
Louis
18th Aug 2017, 12:29 PM
👑 Prometheus 🇸🇬
+ 12
21st Aug 2017, 7:44 PM
David Akhihiero
+ 11
https://code.sololearn.com/cgrSpzZnexR1/?ref=app
18th Aug 2017, 5:58 AM
Bharath_Teki 🇮🇳
+ 9
@Krishna Excellent js implementation. There are many advantages to using a html,css,js for the solution. The allignment for one is much easier. Well done!
18th Aug 2017, 4:24 AM
Louis
+ 9
Hi Pikachu, I thought it out myself. If there is duplication, it is unintentional.
18th Aug 2017, 7:36 AM
Louis
+ 9
Hi... I guess it's still Friday (at least here in Croatia :)). This is my try: https://code.sololearn.com/cDS30H352Qv8/#java I don't really know what to think about it. I wrote it and then glanced at some other solutions and all of them are nuclear science to me... but I hope I'm closing the gap :D Bye & good night.
18th Aug 2017, 9:54 PM
Damir
+ 9
@Onkar. In my code and some others I tested, I got 1 as output with input 1 which is correct. Please specify how you got -1. Also note the challenge asks for N>1.
21st Aug 2017, 1:02 PM
Louis
18th Aug 2017, 10:05 AM
Izi Lior Katie
18th Aug 2017, 5:19 PM
⚛prudhvi⚛
26th Aug 2017, 9:34 AM
Amrendra Kumar
+ 8
https://code.sololearn.com/cc56x7Cm5qL9/?ref=app
13th Feb 2018, 4:55 AM
Saurabh Tiwari
+ 7
Here is mine recursive try. Tried to do the calculation without loops. Hope you like it. https://code.sololearn.com/cpv1gjf0PHqL/?ref=app
18th Aug 2017, 12:01 PM
Pavle Mutic
+ 7
@Pavle Youre the man. like it.Just check the allignment.
18th Aug 2017, 12:15 PM
Louis