Skip to content

Instantly share code, notes, and snippets.

@sledge-1
Created October 17, 2016 00:44
Show Gist options
  • Save sledge-1/891def05b75e21b3d430c8478882c386 to your computer and use it in GitHub Desktop.
Save sledge-1/891def05b75e21b3d430c8478882c386 to your computer and use it in GitHub Desktop.
#!
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