+ 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
74 Answers
+ 45
Good Challenge! My try:
https://code.sololearn.com/W8kskOMgaqdo/?ref=app
+ 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
+ 20
Here is mine in Java.
https://code.sololearn.com/cGTi48cbt8hD/#java
+ 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
+ 14
@Michal, my code is higher up in this thread.
+ 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.
+ 12
@Vari93 and sayan. WOW that was quick, precise and clever. Well done. It took me much longer.
+ 12
Somewhat like mine!
https://www.sololearn.com/discuss/600262/?ref=app
+ 12
Here is mine, wazn't easy 😥
https://code.sololearn.com/c5G4VlU6J91s/?ref=app
+ 11
https://code.sololearn.com/cgrSpzZnexR1/?ref=app
+ 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!
+ 9
Hi Pikachu, I thought it out myself. If there is duplication, it is unintentional.
+ 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.
+ 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.
+ 8
Here is mine (first code)
https://code.sololearn.com/cRCSu8CVTxEQ/?ref=app
+ 8
here is mine
https://code.sololearn.com/celV0cHqmOpS/?ref=app
+ 8
https://code.sololearn.com/cc56x7Cm5qL9/?ref=app
+ 7
Here is mine recursive try.
Tried to do the calculation without loops. Hope you like it.
https://code.sololearn.com/cpv1gjf0PHqL/?ref=app
+ 7
@Pavle Youre the man. like it.Just check the allignment.