Bjorklund’s algorithm

Hi, I am newbie and want to make euclidean sequencer based on this article 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() {

void loop() {
  int t; //total
  int g; //gate
  int r; //remainder
  int i; 
  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) {


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…