From 94c97b4f01bb221fe4c084d7749a4fa94044dd24 Mon Sep 17 00:00:00 2001 From: Nian Lee Date: Mon, 1 Oct 2018 12:25:55 -0700 Subject: [PATCH 1/2] added fibonacci --- contributor_database | 3 ++- snippets/fibonacci_until_num.md | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 snippets/fibonacci_until_num.md diff --git a/contributor_database b/contributor_database index 66bbf0288..67ac62ea8 100644 --- a/contributor_database +++ b/contributor_database @@ -27,4 +27,5 @@ bubble_sort: [Shobhit Sachan](@sachans) has_duplicates: [Rob-Rychs](@Rob-Rychs) keys_only: [Rob-Rychs](@Rob-Rychs) values_only: [Rob-Rychs](@Rob-Rychs) -all_unique: [Rob-Rychs](@Rob-Rychs) \ No newline at end of file +all_unique: [Rob-Rychs](@Rob-Rychs) +fibonnaci_until_num: [Nian Lee](@scraggard) diff --git a/snippets/fibonacci_until_num.md b/snippets/fibonacci_until_num.md new file mode 100644 index 000000000..12dc2fc04 --- /dev/null +++ b/snippets/fibonacci_until_num.md @@ -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 +``` From 1b39ea9adf195513acec0fab0023b75ce3aad780 Mon Sep 17 00:00:00 2001 From: Nian Lee Date: Mon, 1 Oct 2018 12:39:39 -0700 Subject: [PATCH 2/2] added fib --- README.md | 26 ++++++++++++++++++++++++++ contributor_database | 2 +- tag_database | 3 ++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index efff5f76c..7533e385b 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ This project contains plenty of useful snippets which can help beginners and new
View contents
  • average
  • factorial
  • +
  • fibonacci_until_num
  • gcd
  • lcm
  • max_n
  • @@ -462,6 +463,31 @@ factorial(6) # 720
    :arrow_up: Back to top +### fibonacci_until_num +Author:- [Nian Lee](https://www.github.com/scraggard) + + Contributors:- [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) +``` +
    View Examples + +```py +fibonnaci_until_num(5) # 5 +fibonnaci_until_num(15) # 610 +``` +
    + +
    :arrow_up: Back to top + ### gcd Author:- [Rohit Tanwar](https://www.github.com/kriadmin) diff --git a/contributor_database b/contributor_database index 67ac62ea8..6e4f7edf3 100644 --- a/contributor_database +++ b/contributor_database @@ -28,4 +28,4 @@ has_duplicates: [Rob-Rychs](@Rob-Rychs) keys_only: [Rob-Rychs](@Rob-Rychs) values_only: [Rob-Rychs](@Rob-Rychs) all_unique: [Rob-Rychs](@Rob-Rychs) -fibonnaci_until_num: [Nian Lee](@scraggard) +fibonacci_until_num: [Nian Lee](@scraggard) diff --git a/tag_database b/tag_database index 17db9e5fb..e79fd0424 100644 --- a/tag_database +++ b/tag_database @@ -27,4 +27,5 @@ bubble_sort:list has_duplicates:list keys_only:object values_only:object -all_unique:object \ No newline at end of file +all_unique:object +fibonacci_until_num:math