Created
February 9, 2014 16:57
-
-
Save aheld/8902063 to your computer and use it in GitHub Desktop.
This file contains 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 bray(n): | |
if n < 1: return 0 | |
if n == 1: return 1 | |
accumulator = 1 + (2 * n-2) # this is the same as 1 + 2 + 2 +2 .... | |
return accumulator + bray(n-1) | |
for n in range(10): | |
bray(n) | |
print("n=%3d: bray(n) = %s\t square(n): %5d" % (n,bray(n),n*n) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment