Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Spiraling integers

by CountZero (Bishop)
on Aug 28, 2005 at 16:59 UTC ( #487289=note: print w/replies, xml ) Need Help??


in reply to Spiraling integers

In English (you said "in any language"):
  1. On a piece of paper, draw a square with sides equal to n.
  2. Divide the square into n x n equal little squares (call these "cells")
  3. Starting at the leftmost cell in the top row, write in it the figure 1
  4. In the empty cell to the right of the cell you just wrote into, write the value you just wrote plus 1; if there is no empty cell to the right, change your direction of movement to downwards.
  5. Keep moving in the same direction and writing down a number, equal to the one last written plus 1; if there is no empty cell in the direction you were moving, change direction as follows:
    • If you were moving to the right, change to downwards
    • If you were moving downwards, change to left
    • If you were moving to the left, change to upwards
    • If you were moving up, change to right
  6. Stop when the last number written is equal to n x n

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://487289]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2019-02-19 23:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I use postfix dereferencing ...









    Results (105 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 18:53 UTC) Welcome new users!