Merge pull request #38 from scraggard/master

[FEATURE] added fibonacci
This commit is contained in:
Angelos Chalaris
2019-08-19 13:42:15 +03:00
committed by GitHub
4 changed files with 48 additions and 2 deletions

View File

@ -37,6 +37,7 @@ This project contains plenty of useful snippets which can help beginners and new
<details><summary>View contents</summary> <ul><li><a href = "#average"><code>average</code></a></li> <details><summary>View contents</summary> <ul><li><a href = "#average"><code>average</code></a></li>
<li><a href = "#factorial"><code>factorial</code></a></li> <li><a href = "#factorial"><code>factorial</code></a></li>
<li><a href = "#fibonacci_until_num"><code>fibonacci_until_num</code></a></li>
<li><a href = "#gcd"><code>gcd</code></a></li> <li><a href = "#gcd"><code>gcd</code></a></li>
<li><a href = "#lcm"><code>lcm</code></a></li> <li><a href = "#lcm"><code>lcm</code></a></li>
<li><a href = "#max_n"><code>max_n</code></a></li> <li><a href = "#max_n"><code>max_n</code></a></li>
@ -462,6 +463,31 @@ factorial(6) # 720
<br><a href = "#table-of-contents">:arrow_up: Back to top</a> <br><a href = "#table-of-contents">:arrow_up: Back to top</a>
### fibonacci_until_num
<span style="color:grey">Author:-</span> [Nian Lee](https://www.github.com/scraggard)
<span style="color:grey">Contributors:-</span> [Nian Lee](https://www.github.com/scraggard)
Returns the n-th term in a Fibonnaci sequence that starts with 1
A term in a Fibonnaci sequence is the sum of the two previous terms.
This function recursively calls the function to find the n-th term.
```py
def fibonacci_until_num(n):
if n < 3:
return 1
return fibonacci_until_num(n - 2) + fibonacci_until_num(n - 1)
```
<details><summary>View Examples</summary>
```py
fibonnaci_until_num(5) # 5
fibonnaci_until_num(15) # 610
```
</details>
<br><a href = "#table-of-contents">:arrow_up: Back to top</a>
### gcd ### gcd
<span style="color:grey">Author:-</span> [Rohit Tanwar](https://www.github.com/kriadmin) <span style="color:grey">Author:-</span> [Rohit Tanwar](https://www.github.com/kriadmin)

View File

@ -28,4 +28,5 @@ has_duplicates: [Rob-Rychs](@Rob-Rychs)
keys_only: [Rob-Rychs](@Rob-Rychs),[Matteo Veraldi](@mattveraldi) keys_only: [Rob-Rychs](@Rob-Rychs),[Matteo Veraldi](@mattveraldi)
values_only: [Rob-Rychs](@Rob-Rychs) values_only: [Rob-Rychs](@Rob-Rychs)
all_unique: [Rob-Rychs](@Rob-Rychs) all_unique: [Rob-Rychs](@Rob-Rychs)
fermat_test: [Alexander Pozdniakov](@0awawa0) fibonacci_until_num: [Nian Lee](@scraggard)
fermat_test: [Alexander Pozdniakov](@0awawa0)

View File

@ -0,0 +1,18 @@
### fibonacci_until_num
Returns the n-th term in a Fibonnaci sequence that starts with 1
A term in a Fibonnaci sequence is the sum of the two previous terms.
This function recursively calls the function to find the n-th term.
``` python
def fibonacci_until_num(n):
if n < 3:
return 1
return fibonacci_until_num(n - 2) + fibonacci_until_num(n - 1)
```
``` python
fibonnaci_until_num(5) # 5
fibonnaci_until_num(15) # 610
```

View File

@ -27,4 +27,5 @@ bubble_sort:list
has_duplicates:list has_duplicates:list
keys_only:object keys_only:object
values_only:object values_only:object
all_unique:object all_unique:object
fibonacci_until_num:math