I'm presenting an internal workshop to the team on iterative macros using the Collatz Conjecture as a use case where every number reduces to 1 by applying two conditional functions: if odd 3n+1, if even n/2. As an example, 79 reduces to 1 in 35 iterations when just one value runs through the macro. But, when several values, including 79, run through, the number of iterations increases. How do I get the engine.iterationnumber constant to reset to zero?
Sorry, I can't upload an image or a file due to our network settings, but it's a simple iterative macro:
Input -> Filter(Mod(n,2))->Formula from T(n*3+1), Formula from F(n/2) -> Union -> Filter(n=1) -> Formula from T(engine.iterationnumber+1) -> Results output, then iteration output from F.
This works perfectly for just one number through the input. I then have an app that allows the user to select a range of integers that are fed into the macro. If it's just a few numbers, like 77-80, the results are accurate. But, if it's 27-80, it shows that 79 reduces to 1 in 112 iterations. Amp Engine is turned off for both the macro and the app. Alone, 70 reduces in 14 iterations, as part of a range, in 35 iterations.
Should I make this a nested iterative macro? A Batch macro nesting the iterative? This looks like a bug of some sort. Or is there a way to reset the constant as each number is received?
Thanks!!
Joy
Solved! Go to Solution.
You cannot reset the iteration number within an iterative macro. Every time an iterative macro starts, the iteration number begins at 0, then after every iteration, the iteration number increases by one.
Either method you mentioned will work to cause the inner macro to reset (nested iterative vs. iterative nested in batch), but it doesn't seem like that's necessary. The workflow algorithm you described, should work fine to answer your question.
What input are you using? Do you store a duplicate of the input number so that it isn't lost after apply Collatz steps (i.e. 3n+1, n/2), or do you use a RecordID? If you only have one column going through the iterative macro, then your problem may be a sorting issue.
My suspicion is that your output is a sorted list of numbers, and that from the range you included, you got both 78 & 79 as 112 with 80 as 115 (even though it's actually 54 & 55 that take 112 steps).
Here is a workflow that works as you described, but uses an extra column to track input value:
Output:
Happy Solving!!! I wish you the best on your presentation!
Thank you, Andrew! Funny how it's always something so simple with things like this! Just an extra column. Thank you so much!
If your problem has been resolved, please kindly mark the solution so that others can more easily find solutions as well!
Glad things worked out for you!