Bjorklund’s algorithm

Hi, I am newbie and want to make euclidean sequencer based on this article http://archive.bridgesmathart.org/2005/bridges2005-47.pdf. I thought all day, but can not find how to sort an array like this: Dropbox - Error .

Now I have only unsorted array

void setup() {
 Serial.begin(9600);
}

void loop() {
  int t; //total
  int g; //gate
  int r; //remainder
  int i; 
  t=13;
  g=5;
  unsigned int unsorted[t];
     for (i=0;i<t;i++){ 
      if (i<g){
        unsorted[i] = 1;
      }
      else {
        unsorted[i] = 0;
      }
  }
  
  for (i = 0; i < t; i = i + 1) {
  Serial.println(unsorted[i]);
}
delay(5000);
}

See https://ics-web.sns.ornl.gov/timing/Rep-Rate%20Tech%20Note.pdf

Yeah; right.
If you’re dealing with relatively small sequences and don’t care about O(n) efficiency, it looks to me like an O(n2) algorithm would be relatively straight-forward.

while (remainderSeqs > 1) 
  while (remainderSeqs > 1) {
    remainderSeqs -= moveRemainderAfterEachMain(mainSeqSize, RemainderSeqSize, RemainderStart)
    mainSeqSize += remainderSeqSize
  }
  recomputer remainderSeqs at new size
}

I’m don’t think I understand what it’s doing enough to test an implementation, though…