Skip to content

Instantly share code, notes, and snippets.

@phabee
Created Oct 4, 2020
Embed
What would you like to do?
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