Created
August 28, 2022 15:19
Star
You must be signed in to star a gist
This Excel lambda function calculates a Fibonacci-like sequence of numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Produces a sequence of numbers where n_i = n_(i-1) + n_(i-2) | |
We can optionally provide first and second values in the sequence. | |
Otherwise they are assumed to be 1 and 1. | |
*/ | |
FIBONACCI =LAMBDA(seq_length,[first],[second], | |
LET( | |
one,IF(ISOMITTED(first),1,first), | |
two,IF(ISOMITTED(second),1,second), | |
idx,SEQUENCE(seq_length-2), | |
REDUCE(VSTACK(one,two),idx, | |
LAMBDA(a,b,VSTACK(a, CHOOSEROWS(a, -2) + CHOOSEROWS(a, -1)))) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment