How to create a code for Fibonacci series in Appian
Discussion posts and replies are publicly visible
TEST_AddValueToLastInList(list, value): append(ri!list, reverse(ri!list)[1] + reverse(ri!list)[2]), reduce( rule!TEST_AddValueToLastInList(list:_, value:_), {0, 1}, enumerate(30) )
{0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269}
can it be done using localVariables ?
As far as I can tell this function needs to be called recursively (or at least via the reduce() function), hence the expression rule 'TEST_AddValueToLastInList'.
What would local variables add?
But you could store the initial list value "{0,1}" and the numbers "enumerate(30" into locals.
DSAA_FibonacciSeries -------------------------------- a!localVariables( local!input:ri!input, local!result:a!forEach( items: enumerate(ri!input), expression: rule!DSAA_calculateFibSeries(fv!item) ), local!result ) ------------------- DSAA_calculateFibSeries -------------------------- if( ri!numTimes <= 2, 1, sum(rule!DSAA_calculateFibSeries(numTimes: ri!numTimes - 2), rule!DSAA_calculateFibSeries( numTimes: ri!numTimes-1 )) )