Created
October 17, 2016 00:44
-
-
Save sledge-1/891def05b75e21b3d430c8478882c386 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#! | |
import turtle | |
wn = turtle.Screen() | |
alex = turtle.Turtle() | |
fibonacci_cache = {} | |
def fibonacci(n): | |
#if we have cached the value, then return in it | |
if n in fibonacci_cache: | |
return fibonacci_cache[n] | |
#compute Nth term | |
if n == 1: | |
value = 1 | |
elif n == 2: | |
value = 1 | |
elif n > 2: | |
value = fibonacci(n-1) + fibonacci(n - 2) | |
#cache value and return it | |
fibonacci_cache[n] = value | |
for n in range(1,200): | |
alex.forward(fibonacci(n)) | |
aleft.left(fibonacci(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment