How to calculate the current index?

Posted by niko on Stack Overflow See other posts from Stack Overflow or by niko
Published on 2010-05-12T10:14:45Z Indexed on 2010/05/12 10:44 UTC
Read the original article Hit count: 188

Filed under:
|

Hi,

I have written an algorithm which iteratively solves the problem. The first iteration consists of 6 steps and all the following iterations consist of 5 steps (first step is skipped).

What I want to calculate is the current (local) step in the iteration from current global step.

For example if there are 41 steps in total which means there are 8 iterations: indices from 1 to 6 belong to 1st iteration indices from 7 to 11 belong to second iteration ...

For calculating the current iteration I have written the following code:

if(currentStep <= 6)
        iteration = 1;
    else
        iteration = floor((currentStep - 7)/5) + 2;
    end

The problem remains in calculating local steps. in first iteration the performed steps are: 1, 2, 3, 4, 5, 6 in all the following iterations the performing steps are 2, 3, 4, 5, 6

So what has to be done is to transform the array of global steps

[1 2 3 4 5 6 7 8 9 10 11 12 13 ... 41] 

into array of local steps

[1 2 3 4 5 6 2 3 4 5 6 2 3 ... 6].

I would appreciate if anyone could help in finding the solution to a given problem.

Thank you!

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about matlab