Skip to content

Instantly share code, notes, and snippets.

@yyl
Created July 25, 2012 02:13
Show Gist options
  • Save yyl/3173978 to your computer and use it in GitHub Desktop.
Save yyl/3173978 to your computer and use it in GitHub Desktop.
euler 28
def approach1(size):
diagonal = 0
current = 1
for i in range(1, size+1):
current += i
diagonal += current
# decrease the sum if it is the first odd turn
if i%2 != 0:
diagonal -= 1
current += i
diagonal += current
# remove the last turn
diagonal -= current
print diagonal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment