Forum Discussion
Viz
Jan 05, 2021Brass Contributor
Lambda Example: Generate Fibonacci series
In this post, I would like to explain how I have used Lambda to create a function to generate a Fibonacci series array. This example can also be used to understand how to create an array where th...
lori_m
Apr 15, 2023Iron Contributor
Yes REDUCE is the only helper function currently able to process arrays this way. Another approach is to apply SCAN to build up data structures as trees, for example this formula returns first ten fibonacci numbers:
=MAP(SCAN(LAMBDA(i,i),SEQUENCE(10),LAMBDA(x,_,LAMBDA(i,i*x(0)+x(1)))),LAMBDA(fib,fib(0)))but this is very inefficient in Excel as results are not cached (ref: https://realpython.com/fibonacci-sequence-python/ ). I really hope dev teams take note of this community feedback and provide solutions for commonly encountered scenarios like these.
SergeiBaklan
Apr 15, 2023Diamond Contributor
Oops, It took time to understand the formula, still don't sure if I took it correctly or not. Fibonacci and efficiency don't matter, approach is great.