Skip to content

Instantly share code, notes, and snippets.

@CHatmaker
Last active January 27, 2024 15:47
Show Gist options
  • Save CHatmaker/e463f2edd734e40f78c39295e1ff8f7e to your computer and use it in GitHub Desktop.
Save CHatmaker/e463f2edd734e40f78c39295e1ff8f7e to your computer and use it in GitHub Desktop.
5G functions for Excel: Miscellaneous Math
/* Function Description
Aboutλ About this module and links to online resources
Fibonacciλ Determine the nth number in a Fibonacci sequence
*/
/* FUNCTION NAME: Aboutλ
DESCRIPTION:*/ /**Displays the URL to this module's Gist which includes documentation*/
/* ARGS: *None
EXAMPLE: =About()
ERRORS: *None
REVISIONS: Date Developer Description
Mar 03 2023 Craig Hatmaker Original Development
*/
Aboutλ =TEXTSPLIT(
"About:,BXL's math module. Suggested module name: BRM;" &
"Version:,Mar 03 2023;" &
"Gist URL:,https://gist.github.com/CHatmaker/https://gist.github.com/CHatmaker/e463f2edd734e40f78c39295e1ff8f7e;" &
"Website:,https://sites.google.com/site/beyondexcel/home/excel-library/;" &
",;" &
"Function,Description;" &
"Aboutλ,Produces this table;" &
"Fibonacciλ,Determine the nth number in a Fibonacci sequence" ,
",",
";"
);
/* FUNCTION NAME: Fibonacciλ
DESCRIPTION:*/ /**Determine nth number in Fibonacci sequence*/
/* ARGS: n The position of the number to return within the Fibonacci sequence
EXAMPLE =Fibonacciλ(1) Returns 0
=Fibonacciλ(2) Returns 1
=Fibonacciλ(3) Returns 1
=Fibonacciλ(4) Returns 2
=Fibonacciλ(5) Returns 3
=Fibonacciλ(6) Returns 5
*/
Fibonacciλ = LAMBDA(
// Parameter Declarations
n,
// LAMBDA's fromula
LET(
// Validate Parameters
ErrMsg, "n must be a whole number greater than 0",
ErrTst, If( Not(ISNUmber(n)),
ErrMsg,
If( n < 1 , ErrMsg, "")),
// Procedure
Result, If( ErrTst <> "",
ErrMsg,
IF(n <= 2, n - 1, Fibonacciλ(n - 1) + Fibonacciλ(n - 2))),
// Return Result
Result
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment