Did a few exersises, most of the way through serial_logger.
This commit is contained in:
parent
1f4cc71b96
commit
97fb8de5da
8 changed files with 331 additions and 20 deletions
|
@ -1,30 +1,31 @@
|
|||
/* calculates all subsets of the string comb by assigning eatch letter a position in a binary number and counting up. */
|
||||
/* calculates all subsets of the string comb by assigning eatch letter a
|
||||
* position in a binary number and counting up. */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// #define DEBUG
|
||||
|
||||
int main() {
|
||||
char* comb = "ABCD";
|
||||
int count = strlen(comb);
|
||||
// that bitshifting is the same is squaring count
|
||||
int permutations = (1 << count);
|
||||
char *comb = "ABCD";
|
||||
int count = strlen(comb);
|
||||
// that bitshifting is the same is squaring count
|
||||
int permutations = (1 << count);
|
||||
|
||||
printf("string is %s\nthere are %d permutations", comb, permutations);
|
||||
printf("string is %s\nthere are %d permutations", comb, permutations);
|
||||
|
||||
for (unsigned char i = 0; i < permutations; i++) {
|
||||
for (unsigned char j = 0; j < 4; j++) {
|
||||
// when j=0, will result in 0b0001, when j=1, 0b0010, j=2 0b0100.
|
||||
unsigned char mask = 1 << j;
|
||||
for (unsigned char i = 0; i < permutations; i++) {
|
||||
for (unsigned char j = 0; j < 4; j++) {
|
||||
// when j=0, will result in 0b0001, when j=1, 0b0010, j=2 0b0100.
|
||||
unsigned char mask = 1 << j;
|
||||
#ifdef DEBUG
|
||||
printf(" j=%x mask=%x, postmask=%x, i=%x", j, mask, (i & mask), i);
|
||||
printf(" j=%x mask=%x, postmask=%x, i=%x", j, mask, (i & mask), i);
|
||||
#endif /* ifdef DEBUG */
|
||||
if ((i & mask) != 0) {
|
||||
printf(" %c", comb[j]);
|
||||
}
|
||||
if ((i & mask) != 0) {
|
||||
printf(" %c", comb[j]);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue