Skip to content

Instantly share code, notes, and snippets.

@fulmicoton
Created October 26, 2018 07:25
Show Gist options
  • Save fulmicoton/7ec993229f1d89cf2e0a1b607cc27202 to your computer and use it in GitHub Desktop.
Save fulmicoton/7ec993229f1d89cf2e0a1b607cc27202 to your computer and use it in GitHub Desktop.
def fibo(n = 10):
els = []
prev = 1
next = 1
for i in range(n):
(prev, next) = (next, prev+next)
els.append(prev)
return els
def stutter(g, a, b):
memory = []
for i in range(b + 1):
try:
memory.append(g.next())
except:
pass
print "MEMORY", memory
cursor = 0
b = len(memory) - 1
len_memory = len(memory)
while b>=a:
for l in range(a, b + 1):
# if len < len_memory:
print l
yield memory[cursor], memory[(cursor + l)%len(memory)]
try:
memory[cursor] = g.next()
except:
b -= 1
cursor = (cursor + 1) % len(memory)
FIBO = fibo()
print FIBO
for el in stutter(iter(FIBO), 1, 2):
print el
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment