title: How do I change pattern from one array to another and then back
body: <p>I have an original array in C++ that could be containing any numbers and change in length, but this is my example with the following simple content:</p>
  
  <pre><code>{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  </code></pre>
  
  <p>What I want is to change the order of the array
  By splitting the array up in blocks of dynamic size like, let us say 3 (could be something else in size).</p>
  
  <pre><code>int len = 10;
  int blocks = 10/3;
  </code></pre>
  
  <p>And use these values to split the array up in blocks about 3 numbers:</p>
  
  <pre><code>0,1,2 | 3,4,5 | 6,7,8 | 9
  </code></pre>
  
  <p>And then take the first value from first block and next value from the next block like:</p>
  
  <pre><code>0,3, 1,4, 2,5,
  </code></pre>
  
  <p>And then jump two blocks and add next part like:</p>
  
  <pre><code>6,9, 7, 8
  </code></pre>
  
  <p>7 and 8 will be alone since there are no more parts in the last block for these two numbers.
  The complete result should then be like:</p>
  
  <pre><code>0,3,1,4,2,5,6,9,7,8
  </code></pre>
  
  <p>How could I solve this problem with an algorithm when the last block might sometimes not contain a complete set of numbers?</p>
  
  <p>And how could I after that create an algorithm to reverse the result array back to what it was?</p>
  
  <p>And no this isn't an assignment, I'm going to use it to shuffle a soundfile around to make it hard for others to just copy the file and use it however they want.</p>
  
  <p>EDIT: Here is my last test attempt that I got stuck on:</p>
  
  <pre><code>static int test[] = { 0 ,1 ,2, 3, 4, 5, 6, 7, 8, 9};
  static int testTo[] = { -1 ,-1 ,-1, -1, -1, -1, -1, -1, -1, -1};
  int _tmain(int argc, _TCHAR* argv[])
  {
      int len = 10;
      int block = len/3.0;
      for (int i=0;i&lt;len;i=i+block*2)
      {
          for (int y=0;y&lt;block&amp;&amp;i+(y*2)+1&lt;len-1;y++)
          {
              testTo[i+(y*2)] = test[i+y];
              testTo[i+(y*2)+1] = test[(i+block)+y];
          }
      }
      return 0;
  }
  </code></pre>