Brian Jones posted a solution to the Oblong Spiral Puzzle recently.
I don't normally mess with puzzles, but after looking at his solution
I thought I would take a stab at it and see if I could come up with a
solution in Python that was a little less complicated.
The complete definition of the puzzle is on the Code Golf site.
The challenge is to fill in an n x m array with a sequence of
numbers starting at the upper left, and working around the outside,
spiraling inwards. For example:
$ python spiral.py 3 3
1 2 3
8 9 4
7 6 5
$ python spiral.py 4 5
1 2 3 4
14 15 16 5
13 20 17 6
12 19 18 7
11 10 9 8
Spend a few minutes thinking about the problem, then see if your solution looks anything like mine.
Updated to fix link to solution.
0 comments:
Post a Comment