Last active
February 8, 2020 07:50
-
-
Save rileypeterson/834a6a75346662161bc070b3e7020c20 to your computer and use it in GitHub Desktop.
Recursion baby
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
pts = [(-1, 1), (0, 1), (1, 0), (2, 2), (3, 3), (4, 2)] | |
def fd(*points, values=None): | |
if values is None: | |
values = [] | |
if len(points) == 2: | |
x0, y0 = points[0] | |
x1, y1 = points[1] | |
val = (y1 - y0) / (x1 - x0) | |
values.append(val) | |
return val, values | |
num = (fd(*points[1:], values=values)[0] - fd(*points[:-1], values=values)[0]) | |
denom = (points[1:][-1][0] - points[:-1][0][0]) | |
val = num / denom | |
values.append(val) | |
return val, values | |
l = [(0, 1), (1, 0), (2, 2)] | |
print(fd(*l)) | |
l = [(1, 0), (2, 2), (3, 3)] | |
print(fd(*l)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment