Skip to content

Instantly share code, notes, and snippets.

@phabee
Created October 4, 2020 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phabee/db24d729e617763e2628aa55b7bf56cb to your computer and use it in GitHub Desktop.
Save phabee/db24d729e617763e2628aa55b7bf56cb to your computer and use it in GitHub Desktop.
library(tictoc)
fibonacci <- function(n) {
if (n > 1) {
return (fibonacci(n-2) + fibonacci(n-1))
} else if (n == 1) {
return (1)
}
return(0)
}
tic()
a = fibonacci(30)
toc()
cat("fibonacci(30)=", a)
@phabee
Copy link
Author

phabee commented Oct 4, 2020

Simple demonstration of recursive fibonacci series in R.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment