Skip to content

Instantly share code, notes, and snippets.

@DawidNowak
Created November 12, 2017 12:38
Show Gist options
  • Save DawidNowak/1d26bd242129fcbb7cd4df2f0a73663b to your computer and use it in GitHub Desktop.
Save DawidNowak/1d26bd242129fcbb7cd4df2f0a73663b to your computer and use it in GitHub Desktop.
Fibonacci python
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