Created
July 25, 2012 02:13
-
-
Save yyl/3173978 to your computer and use it in GitHub Desktop.
euler 28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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