fibonacci: Calculate a fibonacci sequence

Description Usage Arguments Details Examples

View source: R/fibonacci.R

Description

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.

Usage

1
fibonacci(seq_length = 10, first_num = 0, second_num = 1)

Arguments

seq_length

The length of the sequence as a number. The sequence length has to be greater than or equal to 2 (seq_length >= 2). The default is 10.

first_num

The starting point of the sequence. Use any positive number that comes before second_num (first_num < second_num). The default is 0.

second_num

The next number in the sequence after first_num. Use any positive number that comes after first_num (second_num > first_num). The default is 1.

Details

If using the default first and second numbers of 0 and 1 R will return Inf starting at element number 1478.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## 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

## End(Not run)
fibonacci(8, 10, 12)  # correct!
fibonacci(seq_length = 20, first_num = 10, second_num = 15)  # yay!
fibonacci(30)
fibonacci()

fibonacci(1500)[1477]
fibonacci(1500)[1478]
fibonacci(1500)[1500]

Paul-James/pjames documentation built on Aug. 9, 2019, 12:18 p.m.