How do I calculate the current index?
I wrote an algorithm that iteratively solves the problem. The first iteration consists of 6 steps, and all subsequent iterations consist of 5 steps (the first step is skipped).
What I want to calculate is the current (local) step in the iteration from the current global step.
For example, if there are 41 steps in total, that is, 8 iterations: indices 1 to 6 refer to the 1st iteration indices 7 to 11 refer to the second iteration ...
To calculate the current iteration, I wrote the following code:
if(currentStep <= 6)
iteration = 1;
else
iteration = floor((currentStep - 7)/5) + 2;
end
The problem remains in the computation of local steps. at the first iteration, the stages are: 1, 2, 3, 4, 5, 6 in all subsequent iterations, steps 2, 3, 4, 5, 6 are performed
So what needs to be done is transform the array of global steps
[1 2 3 4 5 6 7 8 9 10 11 12 13 ... 41]
to an array of local steps
[1 2 3 4 5 6 2 3 4 5 6 2 3 ... 6]
...
I would be grateful if someone could help find a solution to this problem.
Thanks!
a source to share