View source: R/collatz_function.R
collatz_function | R Documentation |
Returns the output of a single application of a Collatz-esque function.
collatz_function(n, P = 2, a = 3, b = 1)
n |
(numeric|bigz) The value on which to perform the Collatz-esque function |
P |
(numeric|bigz): Modulus used to divide n, iff n is equivalent to (0 mod P). Default is 2. |
a |
(numeric|bigz) Factor by which to multiply n. Default is 3. |
b |
(numeric|bigz) Value to add to the scaled value of n. Default is 1. |
This function will compute and return the result of applying one iteration of a parameterised Collatz-esque function. Although it will operate with integer inputs, for overflow safety, provide a gmp Big Integer ('bigz').
a numeric, either in-built or a bigz from the gmp library.
# Returns the output of a single application of a Collatz-esque function. # Without `gmp` or parameterisation, we can try something simple like collatz_function(5) collatz_function(16) # If we want change the default parameterisation we can; collatz_function(4, 5, 2, 3) # Or if we only want to change one of them collatz_function(3, a=-2) # All the above work fine, but the function doesn't offer protection against # overflowing integers by default. To venture into the world of arbitrary # integer inputs we can use an `as.bigz` from `gmp`. Compare the two; collatz_function(99999999999999999999) collatz_function(as.bigz("99999999999999999999"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.