sure
anything in uppercase would be a #define'd constant
Code:
int main (void) {
srand(time(0));
testUnique();
permutation ("abc");
return EXIT_SUCCESS;
}
int allUnique(char *string) {
int length = strlen(string);
int i,j;
for (i=0; i<length;i++) {
for (j=i+1; j<length;j++) {
if (string[i] == string[j]) {
return 1;
}
}
}
return 0;
}
void permutation (char *string) {
int length = strlen(string);
int prime = 1;
int numOfPermutations = 1;
int i, j=0;
int random;
char guess[length+1];
int same;
for (i=length; i>0; i--) {
numOfPermutations *= i;
}
char permutations[numOfPermutations][length+1];
int upTo = 0;
strcpy(permutations[upTo], string);
upTo++;
int index;
while (upTo != numOfPermutations) {
index = 0;
while (index<length) {
random = rand() % length;
guess[index] = string[random];
index++;
}
same = FALSE;
for (i=0; i<upTo && same == FALSE; i++) {
if (strcmp(guess, permutations[i]) == 0 ) {
same = TRUE;
i = upTo;
} else {
printf("first %s != %s %d\n", guess, permutations[i], i);
/*************
problem here
************/
}
}
if (same == FALSE && allUnique(guess) == 0) {
// this indicates that the break condition for the previous for loop
// was i<upTo, that is, we found a unique string
printf("string %s is unique\n", guess);
strcpy (permutations[upTo], guess);
upTo++;
} else if (strcmp (guess, "abc") == 0 && prime%ABC!=0) {
printf("second %s\n", guess);
/*************
problem here
************/
}
}
printf("showing all permutations\n");
for (i=0; i<numOfPermutations; i++) {
printf("%s\n", permutations[i]);
}
}