Created
August 6, 2014 00:50
[8/04/2014] Challenge #174 [Easy] Thue-Morse Sequences /r/dailyprogrammer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <stdbool.h> | |
int main(int argc, char *argv[]){ | |
int sequence_count; | |
if(argc>1){ | |
sequence_count = atoi(argv[1]); | |
}else{ | |
printf("%s SIZE",argv[0]); | |
} | |
const int array_size = (int) pow(2,sequence_count); | |
int i,x; | |
int current_size = 1; | |
//2^n is the size of the array we need; | |
bool array[array_size]; //first is 0 | |
array[0] = false; | |
for(i=0;i<sequence_count;i++){ | |
for(x=0;x<current_size;x++){ | |
array[x+current_size] = !array[x]; | |
} | |
current_size *= 2; | |
} | |
for(i=0;i<array_size;i++){ | |
if(array[i]){ | |
printf("1"); | |
}else{ | |
printf("0"); | |
} | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment