Learning more about loops and how to efficiently utilize them. Something is stumping me however. I would like to use the list that is output from a function as the input for the same function when it is run again. I would like to iterate this function for say 20 times using the output from the previous ‘generation’ as the input to calculate the next ‘generation.’
Input -> (0 5 8) [ Function Calculate the difference between successive numbers (0 5 8) -> (5 3) Reverse that list (5 3) -> (3 5) Create series using those values starting from LAST number in list (8) + 3 + 5 -> (8 11 16) ] Output -> (8 11 16)
Use that output list as the input into the function and run it again;
Input -> (8 11 16) [ Function Calculate the difference between successive numbers (8 11 16) -> (3 5) Reverse that list (3 5) -> (5 3) Create series using those values starting from LAST number in list (16) + 5 + 3 -> (16 21 24) ] Output -> (16 21 24)
Continue for another 19 generations outputting the list each time.
I can do this by stacking multiple instances of the same function but this doesn’t really feel like the most efficient or ‘right’ way to implement this. I have a feeling that the accumulator needs to be used in an loop but I cannot figure out how to set it up without getting the “Impossible to connect, this would create a cycle” error.
I have attached my basic implementation as explained above (list flip add) and the actual problem that I am working on (Retrograde Interval Link).
Any suggestions are very welcome!