Created
October 22, 2019 15:33
-
-
Save fakedrake/cf12b1e163992800fffb1ea1b72b0e50 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
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