Last active
May 5, 2022 19:07
-
-
Save eecsmap/e88914cece030dab4b882a6cbca30d63 to your computer and use it in GitHub Desktop.
cs61a
This file contains 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 VirFib(): | |
"""A Virahanka Fibonacci number. | |
>>> start = VirFib() | |
>>> start | |
VirFib object, value 0 | |
>>> start.next() | |
VirFib object, value 1 | |
>>> start.next().next() | |
VirFib object, value 1 | |
>>> start.next().next().next() | |
VirFib object, value 2 | |
>>> start.next().next().next().next() | |
VirFib object, value 3 | |
>>> start.next().next().next().next().next() | |
VirFib object, value 5 | |
>>> start.next().next().next().next().next().next() | |
VirFib object, value 8 | |
>>> start.next().next().next().next().next().next() # Ensure start isn't changed | |
VirFib object, value 8 | |
""" | |
def __init__(self, value=0): | |
self.value = value | |
def next(self): | |
"*** YOUR CODE HERE ***" | |
ans = VirFib(int(not self.value) or self.value + self.prev) | |
ans.prev = self.value | |
return ans | |
def __repr__(self): | |
return "VirFib object, value " + str(self.value) | |
import doctest; doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment