Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Spiraling integers

by CountZero (Bishop)
on Aug 28, 2005 at 20: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 studying the Monastery: (5)
As of 2019-10-23 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?