Python Forum
Creating a circular matrix with one input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a circular matrix with one input
#19
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"
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.
Reply


Messages In This Thread
RE: Creating a circular matrix with one input - by perfringo - Oct-02-2020, 01:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with a Matrix nxn with black and white input Rosko 3 1,986 Nov-24-2019, 07:39 AM
Last Post: buran
  Creating a wavelet matrix pingaan 4 2,523 May-26-2019, 06:25 PM
Last Post: heiner55
  define a diagonal matrix from a matrix amalalaoui 1 2,368 May-15-2019, 01:12 PM
Last Post: ichabod801
  Code for a circular wire?? hiphopopot0mous 11 6,622 Dec-03-2017, 06:23 PM
Last Post: micseydel
  Creating lists or arrays as the input nickalvar 4 4,232 May-03-2017, 04:46 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020