Last active
December 17, 2015 07:29
-
-
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.
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
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))*" "+ " ", | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment