Skip to content

Instantly share code, notes, and snippets.

@travisperson
Created April 1, 2012 22:22
Show Gist options
  • Save travisperson/2279134 to your computer and use it in GitHub Desktop.
Save travisperson/2279134 to your computer and use it in GitHub Desktop.
Printing a Squares Coordinates

Printing a Squares Coordinates

Write a single function that takes an integer 'n' as a parameter representing the length of a single side of a square.

Print all the integer coordinate points that make up the square starting at (0,0) and going clockwise around (spiraling to the center). You must not print the same coordinate twice.

Note: The x coordinates increase as you move to the right, and the Y coordinates increase as you go down.

(X,Y)      X Increasing ->
  +------------------------- 
Y |
  |
I |
n |
c |
r |
e |
a |
s |
i |
g |
  |
| |
\/|

Example:

Square of side 3:

(0,0)
(1,0)
(2,0)
(2,1)
(2,2)
(1,2)
(0,2)
(0,1)
(1,1)

Visual:

Alt text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment