This issue is a discussion for contributors to collaborate in getting ready to be featured in 48in24. Please refer to this forum topic for more info.
We will be featuring Spiral Matrix from Jul 09 onwards.
Staff jobs
These are things for Erik/Jeremy to do:
☐ Check/update exercise in Problem Specifications
☐ Create + schedule video
Community jobs
For each track:
Implement Spiral Matrix
Add approaches (and an approaches introduction!) for each idiomatic or interesting/educational approach.
Add video walkthroughs (record yourself solving and digging deeper into the exercise).
Highlight up to 16 different featured exercises (coming soon)
Existing Approaches
You can use these as the basis for approaches on your own tracks. Feel free to copy/paste/reuse/rewrite/etc as you see fit! Maybe ask ChatGPT to translate to your programming language.
I’m not sure if you have any solution that walks the spiral using complex values. My iteration 3 walks from 1..n and iteration 4 walks from n..1. I think iteration 4 is simpler. It starts at the center, rotates whenever there is no value set at the adjacent location and then advances forward one step.
Here i’m adapting in F# the last algorithm described here.
In short it is based on the fact that the minus scan of the inverse permutation of the flattened spiral yields a predictable pattern ([1; n; -1; -n] for the inward counter-clockwise spiral). From this pattern you can create the spiral quite fast as shown in last section of the article.