Sep-25-2020, 11:35 AM
Hi everyone, I have a homework and couldn't solve the following question:
Out an n×n table filled with numbers from 1 to n^2 in a spiral starting from the upper left corner and twisted clockwise, as shown in the example (here n=5):
Sample Input:
5
Sample Output:
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
I am a beginner in Python and I can even barely work with the lists. I have found some similar solutions on the internet but I was not sure what I am looking at since I don't know the advanced methods yet. I know only loops, lists, strings etc. Could anyone help me to solve the question without advanced methods which wouldn't be very complicated for me?
Out an n×n table filled with numbers from 1 to n^2 in a spiral starting from the upper left corner and twisted clockwise, as shown in the example (here n=5):
Sample Input:
5
Sample Output:
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
I am a beginner in Python and I can even barely work with the lists. I have found some similar solutions on the internet but I was not sure what I am looking at since I don't know the advanced methods yet. I know only loops, lists, strings etc. Could anyone help me to solve the question without advanced methods which wouldn't be very complicated for me?