Oct-02-2020, 01:51 PM
There are several ways to solve this problem and there is possibility to apply 'moves' to indices directly without need to moves dictionary.
My thinking was something like - how to fill outer line with consecutive numbers. I solved it with four for-loops using size of n. Then I added for-loop for 'layers/cycles' (how many times to repeat this operation) on top of that and index adjustment (inner layer boundaries are smaller). This solution does not need any manual adjustment - just value of n and it works on square matrices of all sizes.
To emit consecutive values I used iterator and calling next() on it. This may qualify as 'non-beginner'. It can be easily refactored though.
For this particular solution I can provide a hint - "if we go right then going left is reverse and if we are going down then going up is reverse, but keep in mind how range works"
My thinking was something like - how to fill outer line with consecutive numbers. I solved it with four for-loops using size of n. Then I added for-loop for 'layers/cycles' (how many times to repeat this operation) on top of that and index adjustment (inner layer boundaries are smaller). This solution does not need any manual adjustment - just value of n and it works on square matrices of all sizes.
To emit consecutive values I used iterator and calling next() on it. This may qualify as 'non-beginner'. It can be easily refactored though.
For this particular solution I can provide a hint - "if we go right then going left is reverse and if we are going down then going up is reverse, but keep in mind how range works"
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.