/* 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 inputstack, *stack; int i, j, k, stacksize, val, res; //char *ops="+-*/", *opscomb; //int len_ops=strlen(ops), ncombs, nops; int ncombs, nstacks, ntrees, nops; TREE *tree; int intarray[1024]; int eval; char *comb; 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; gen_combinations(nops); //ncombs=ncombinations(len_ops, nops); ncombs=n_combs(); print_combs(); printf("target=%d\nstacksize=%d\nops_comb=%d\n", target, stacksize, ncombs); set_target(target); //printf("len_ops=%d\nnops=%d\nops_comb=%d\n", len_ops, nops, ncombs); //stack=new_stack(stacksize, "Main Stack", 1); strcpy(inputstack.name, "initial"); 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)); */ gen_tree(intarray, nops, 0, 0); printf("operators combinations : %d\n", ncombs); nstacks=n_stacks(); ntrees=n_trees(); printf("nstacks=%d\nncombs=%d\nntrees=%d\n", nstacks, ncombs, ntrees); //for (k=0; khead, 0, stack->stack, comb, &ncalcs); #ifdef DEBUG1 if (eval > 0) { printf("============================== %d, %d, %d\n", i, j, k); print_tree(tree, 0); print_comb(j); print_stack(stack, 0); printf("eval=%d - calcs=%d\n", eval, ncalcs); } #endif } } //opscomb=combination(ops, nops, i); //printf("OPS=%s\n", opscomb); //eval=eval_node(tree->head, 0, stack->stack, nth_comb(0)); //printf("eval=%d\n", eval); //set_ops_stack(stack, opscomb); //print_stack(stack, 0); //res=eval_stack(stack); //printf("EVAL=%d\n", res); } printf("\n"); print_bests(); exit(0); }