Skip to content

Instantly share code, notes, and snippets.

@fakedrake
Created October 22, 2019 15:33
Show Gist options
  • Save fakedrake/cf12b1e163992800fffb1ea1b72b0e50 to your computer and use it in GitHub Desktop.
Save fakedrake/cf12b1e163992800fffb1ea1b72b0e50 to your computer and use it in GitHub Desktop.
class RingBuffer(object):
def __init__(self, data):
self._data = data
def __getitem__(self, i):
return self._data[i % len(self)]
def __setitem__(self, i,v):
self._data[i % len(self)] = v
def __len__(self):
return len(self._data)
def fib(n):
rb = RingBuffer([1,1])
for i in range(2,n):
rb[i] = rb[i-1] + rb[i-2]
return rb[n-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment