chore(Python): rename n-th_fibonacci_number.py to nth_fibonacci_number.py (#664)
parent
88ab2025be
commit
63cdb35173
|
@ -19,7 +19,7 @@
|
|||
|
||||
## Recursion
|
||||
- [Factorial](recursion/factorial.py)
|
||||
- [n-th Fibonacci number](recursion/n-th_fibonacci_number.py)
|
||||
- [n-th Fibonacci number](recursion/nth_fibonacci_number.py)
|
||||
- [Recursive Insertion Sort](recursion/recursive_insertion_sort.py)
|
||||
|
||||
## Scheduling
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
# Function for nth fibonacci number - Using recursion
|
||||
# Taking 1st two fibonacci numbers as 0 and 1
|
||||
|
||||
FibArray = [1]
|
||||
def fibonacci(n):
|
||||
if n<0:
|
||||
print("Incorrect input")
|
||||
if n == 0:
|
||||
return 0
|
||||
elif n<= len(FibArray):
|
||||
return FibArray[n-1]
|
||||
else:
|
||||
temp_fib = fibonacci(n-1)+fibonacci(n-2)
|
||||
FibArray.append(temp_fib)
|
||||
return temp_fib
|
||||
|
||||
# Driver Program
|
||||
print(fibonacci(100))
|
|
@ -0,0 +1,21 @@
|
|||
"""
|
||||
Function for nth fibonacci number - Using recursion
|
||||
Taking 1st two fibonacci numbers as 0 and 1
|
||||
"""
|
||||
|
||||
FibArray = [1]
|
||||
def fibonacci(n_val):
|
||||
"""Fibonacci Number Main Function"""
|
||||
if n_val < 0:
|
||||
sol = "Incorrect input"
|
||||
elif n_val == 0:
|
||||
sol = 0
|
||||
elif n_val <= len(FibArray):
|
||||
sol = FibArray[n_val-1]
|
||||
else:
|
||||
temp_fib = fibonacci(n_val-1)+fibonacci(n_val-2)
|
||||
FibArray.append(temp_fib)
|
||||
sol = temp_fib
|
||||
return sol
|
||||
# Driver Program
|
||||
print(fibonacci(100))
|
Loading…
Reference in New Issue