Skip to content

Instantly share code, notes, and snippets.

@crabtw
Created January 6, 2009 18:25
Show Gist options
  • Save crabtw/43931 to your computer and use it in GitHub Desktop.
Save crabtw/43931 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int num = 0;
int times = 0;
void check(int list[]) {
int sum = 0;
int product = 1;
for(int i = 0; i < 9; ++i) {
sum += list[i];
product *= list[i];
}
if(sum == 45 && product == 362880) {
for(int i = 0; i < 9; ++i) {
printf("%d", list[i]);
}
printf("\n");
++num;
}
}
void gen(int list[]) {
for(int val0 = 1; val0 <= 9; ++val0) {
list[0] = val0;
for(int val1 = 1; val1 <= 9; ++val1) {
list[1] = val1;
for(int val2 = 1; val2 <= 9; ++val2) {
list[2] = val2;
for(int val3 = 1; val3 <= 9; ++val3) {
list[3] = val3;
for(int val4 = 1; val4 <= 9; ++val4) {
list[4] = val4;
for(int val5 = 1; val5 <= 9; ++val5) {
list[5] = val5;
for(int val6 = 1; val6 <= 9; ++val6) {
list[6] = val6;
for(int val7 = 1; val7 <= 9; ++val7) {
list[7] = val7;
for(int val8 = 1; val8 <= 9; ++val8) {
list[8] = val8;
check(list);
++times;
}}}}}}}}}
}
int main(int argc, char *argv[]) {
int list[] = {1,1,1,1,1,1,1,1,1};
gen(list);
printf("(num, times) = (%d, %d)\n", num, times);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment