Takes a sequence length and any two positive numbers in order to produce a fibonacci sequence. The fibonacci sequence is returned as a vector of numbers.
fibonacci(seq_length = 10, first_num = 0, second_num = 1)
seq_length | The length of the sequence as a number. The sequence length has to be greater than or equal to 2 ( |
---|---|
first_num | The starting point of the sequence. Use any positive number that comes before second_num ( |
second_num | The next number in the sequence after first_num. Use any positive number that comes after first_num ( |
If using the default first and second numbers of 0
and 1
R will return Inf
starting at element number 1478
.
# NOT RUN { fibonacci('eight', 2, -1) # wrong #1 fibonacci(8, 2, -1) # wrong #2 fibonacci(8, 2, 1) # wrong #3 fibonacci(8, 2, 2) # wrong #4 # }fibonacci(8, 10, 12) # correct!#> [1] 10 12 22 34 56 90 146 236fibonacci(seq_length = 20, first_num = 10, second_num = 15) # yay!#> [1] 10 15 25 40 65 105 170 275 445 720 1165 1885 #> [13] 3050 4935 7985 12920 20905 33825 54730 88555fibonacci(30)#> [1] 0 1 1 2 3 5 8 13 21 34 #> [11] 55 89 144 233 377 610 987 1597 2584 4181 #> [21] 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229fibonacci()#> [1] 0 1 1 2 3 5 8 13 21 34fibonacci(1500)[1477]#> [1] 1.306989e+308fibonacci(1500)[1478]#> [1] Inffibonacci(1500)[1500]#> [1] Inf