/* compte-est-bon.c - should one day solve this game... * * $ make compte-est-bon * $ ./compte-est-bon target n1 n2 [...n6] * * At least 2 "n" are mandatory, and no more than 6 are allowed. * */ #include #include #include #include #include #include "lceb.h" int main(ac, av) int ac; char **av; { unsigned target; STACK *stack; int i, stacksize, val, res; char *ops="+-*/", *opscomb; int len_ops=strlen(ops), ncombs, nops; if (ac < 4 || ac > 2+MAXINPUT) { fprintf(stderr, "usage: %s target n1 n2 [...n%d]\n", *av, MAXINPUT); exit(1); } target=atoi(av[1]); stacksize=2*(ac-2)-1; nops=ac-2-1; ncombs=ncombinations(len_ops, nops); printf("target=%d\nstacksize=%d\nops_comb=%d\n", target, stacksize, ncombs); printf("len_ops=%d\nnops=%d\nops_comb=%d\n", len_ops, nops, ncombs); stack=new_stack(stacksize, "Main Stack"); for (i=2; istack, 0, stack->last-1); print_stack(stack, 1); i=1; do { printf("permutation %2d: ", i++); print_stack(stack, 0); } while (permute_stack(stack->stack, stack->last)); printf("operators combinations (%d) = ", ncombs); for (i=0; i