chore(Python): rename n-th_fibonacci_number.py to nth_fibonacci_number.py (#664)

pull/669/head
Alim Kerem Erdoğmuş 2022-01-07 15:59:22 +03:00 committed by GitHub
parent 88ab2025be
commit 63cdb35173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 19 deletions

View File

@ -19,7 +19,7 @@
## Recursion ## Recursion
- [Factorial](recursion/factorial.py) - [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) - [Recursive Insertion Sort](recursion/recursive_insertion_sort.py)
## Scheduling ## Scheduling

View File

@ -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))

View File

@ -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))