Lesson 6
This commit is contained in:
35
06/Optional04.c
Normal file
35
06/Optional04.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int hats[6] = {0};
|
||||
int count = 0;
|
||||
|
||||
void nextChild(int childIndex, int whiteRemaining, int blackremaining) {
|
||||
int i;
|
||||
if (childIndex == 6) {
|
||||
count++;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (hats[i] == -1) {
|
||||
printf("White");
|
||||
}
|
||||
else {
|
||||
printf("Black");
|
||||
}
|
||||
printf("\t");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
if (whiteRemaining > 0) {
|
||||
hats[childIndex] = -1;
|
||||
nextChild(childIndex + 1, whiteRemaining - 1, blackremaining);
|
||||
}
|
||||
if (blackremaining > 0) {
|
||||
hats[childIndex] = 1;
|
||||
nextChild(childIndex + 1, whiteRemaining, blackremaining - 1);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
nextChild(0, 3, 3);
|
||||
printf("Total: %d", count);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user