Skip to content

Instantly share code, notes, and snippets.

@mgold
Last active December 17, 2015 07:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgold/5573327 to your computer and use it in GitHub Desktop.
Save mgold/5573327 to your computer and use it in GitHub Desktop.
Play with the differences between linear values, quadratic values, exponential values, and whatever else you like.
DEPTH = 6
LENGTH = 12
#Change me!
def f(i):
return i
#also try:
#return i**2
#return 2**i
vals = [[f(i) for i in range(1,LENGTH)]]
for i in range(DEPTH):
old = vals[-1]
current = []
for j in range(len(old)-1):
current.append(old[j+1]-old[j])
vals.append(current)
for level in range(len(vals)):
if len(vals[level]) == 0:
break
print level*" ",
for x in vals[level]:
outstr = '%+g' % round(x,3)
print outstr + (6-len(outstr))*" "+ " ",
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment