Skip to content

Instantly share code, notes, and snippets.

@encodes1
Created May 9, 2013 13:02
Show Gist options
  • Save encodes1/5547311 to your computer and use it in GitHub Desktop.
Save encodes1/5547311 to your computer and use it in GitHub Desktop.
Week 1 - Challenge 2 - solution
# 3 x 3 grid, has 1 3*3, 4 2*2, 9 1*1
# the easy way to calculate this is to subtract the number you need from the width
# so 2 x 2 in a 3 x 3 grid would be (3 -(2-1)) * (3 -(2-1)) = 4
gridSize = 9
total = 0
# first we start with the smallest square and go up to the widest square
for x in range(1,gridSize+1):
if x ==1:
total = total + (gridSize * gridSize)
else:
total = total + (gridSize - (x-1)) * (gridSize - (x-1))
print total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment