Skip to content

Instantly share code, notes, and snippets.

@aheld
Created February 9, 2014 16:57
Show Gist options
  • Save aheld/8902063 to your computer and use it in GitHub Desktop.
Save aheld/8902063 to your computer and use it in GitHub Desktop.
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