+ 17

Challenge: make a spiral pattern

example: if user input the no. of rows =5 then output should be 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

5th Feb 2018, 12:58 AM
Shruti
Shruti - avatar
17 Respostas
5th Feb 2018, 12:34 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 25
@Shruti Thank you so much 🤗 for choosing my answer 😊 for TheBest !! 😆👍🤓 I'm glad you Like it !! 😉
5th Feb 2018, 12:56 PM
Danijel Ivanović
Danijel Ivanović - avatar
5th Feb 2018, 12:31 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 11
https://www.sololearn.com/discuss/633313/?ref=app
5th Feb 2018, 10:52 AM
Louis
Louis - avatar
+ 9
<script type="text/javascript"> spiralArray = function (edge) { var arr = Array(edge), x = 0, y = edge, total = edge * edge--, dx = 1, dy = 0, i = 0, j = 0; while (y) arr[--y] = []; while (i < total) { arr[y][x] = i++; x += dx; y += dy; if (++j == edge) { if (dy < 0) {x++; y++; edge -= 2} j = dx; dx = -dy; dy = j; j = 0; } } return arr; } // T E S T: arr = spiralArray(edge = 5); for (y= 0; y < edge; y++) { document.write(arr[y].join(" ")+"<br>"); } </script>
5th Feb 2018, 9:10 AM
Ankur Dutta Jha
Ankur Dutta Jha - avatar
13th Feb 2018, 4:48 AM
Saurabh Tiwari
Saurabh Tiwari - avatar
+ 8
Change 3rd last line var edge=prompt("Type your number");
5th Feb 2018, 9:14 AM
Ankur Dutta Jha
Ankur Dutta Jha - avatar
+ 7
?
5th Feb 2018, 7:54 AM
Shruti
Shruti - avatar
5th Feb 2018, 7:59 PM
Pedro Demingos
Pedro Demingos - avatar
6th Feb 2018, 4:00 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
6th Feb 2018, 5:53 AM
davy hermans
davy hermans - avatar
+ 4
https://code.sololearn.com/cDl89f5732Yo/?ref=app
13th Feb 2018, 11:42 AM
...
6th Feb 2018, 7:17 PM
Mister Zioło
Mister Zioło - avatar
+ 2
https://code.sololearn.com/cLdw7u9I3GvY/?ref=app
6th Feb 2018, 10:53 PM
David Handl
David Handl - avatar
23rd Feb 2018, 2:59 PM
Marlon Canlas
Marlon Canlas - avatar
+ 2
https://code.sololearn.com/c3iqKylTbk46/?ref=app
21st Mar 2018, 3:27 PM
Abhimanyu Gupta
Abhimanyu Gupta - avatar
21st Jul 2020, 12:57 AM
shubham kumar
shubham kumar - avatar