[ create a new paste ] login | about

Link: http://codepad.org/4AqJ2d5O    [ raw code | output | fork ]

C, pasted on Apr 14:
void printBinary(char *box, int num){
  int i, j;
  for(i = 0; i < num; i++){
    for(j = 3; j >= 0; j--){
      printf("%d", (box[i] >> j) & 0x01);
    }
    putchar(' ');
  }
  puts("");
}

void shuffle(char *buf, int num){
  int i, j, k, l;
  char box[num - 1];

  for(i = 0; i < num; i++){
    for(j = 0; j < num; j++){
      if(buf[i] < buf[j]){
        box[0] = buf[i] | buf[j];
        l = 0;

        for(k = 0; k < num; k++){
          if(!(buf[k] & box[0]) && !(buf[k] & box[0]))
            box[++l] = buf[k];
        }
        printBinary(box, num - 1);
      }
    }
  }
}

int main (void){
  char buf[] = {0x01, 0x02, 0x04, 0x08};

  shuffle(buf, 4);
  return 0;
}


Output:
1
2
3
4
5
6
0011 0100 1000 
0101 0010 1000 
1001 0010 0100 
0110 0001 1000 
1010 0001 0100 
1100 0001 0010 


Create a new paste based on this one


Comments: