let's say we need to print: (for n = 4)
1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7
this is just a sample for n = 4, the algorithm should be generalized for all integers. I thought and tried to code thinking for the spiral rotation of the indices going here, that is
element: 1 - 2 - 3 - 4 - 5...->16 indexes: 00-01-02-03-13-23...-21
but this spiral rotation of the index does not give me enough picture to enter the full algorithm.
then I took a completely different approach by checking the index number. row and column printed sequentially:
row coloumn 1> 0 -> n-1 2> n-1 -> 0 3> 1 -> n-2 4> n-2 -> 1
but I'm still stuck in writing an algorithm for this. I donβt want my guys to write down codes in response, so just
correct me in my algorithms mentioned above, or if you have any new algorithm for this, please provide a new way to solve this problem.
source share