Created
November 12, 2017 12:38
-
-
Save DawidNowak/1d26bd242129fcbb7cd4df2f0a73663b to your computer and use it in GitHub Desktop.
Fibonacci python
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 FibonacciService: | |
def GetNext(self, num1: int, num2: int) -> int: | |
return num1 + num2 | |
def GenerateList(self, length: int) -> list: | |
res = [] | |
if length >= 1: | |
res.append(1) | |
if length >= 2: | |
res.append(1) | |
if length >= 3: | |
for x in list(range(3, length+1)): | |
res.append(self.GetNext(res[-2], res[-1])) | |
return res | |
fib = FibonacciService() | |
print(str(fib.GenerateList(0))) | |
print(str(fib.GenerateList(1))) | |
print(str(fib.GenerateList(2))) | |
print(str(fib.GenerateList(10))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment