Skip to content

Instantly share code, notes, and snippets.

@ncalm
Created August 28, 2022 15:19
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ncalm/a57db4074fdf318d49f2bfb9b5ca78ee to your computer and use it in GitHub Desktop.
This Excel lambda function calculates a Fibonacci-like sequence of numbers
/*
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