started migration stack->tree
This commit is contained in:
76
lceb.c
76
lceb.c
@@ -14,17 +14,20 @@
|
||||
#include <string.h>
|
||||
#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;
|
||||
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);
|
||||
@@ -33,36 +36,73 @@ int main(ac, av)
|
||||
target=atoi(av[1]);
|
||||
stacksize=2*(ac-2)-1;
|
||||
nops=ac-2-1;
|
||||
ncombs=ncombinations(len_ops, nops);
|
||||
|
||||
printf("A\n");
|
||||
gen_combinations(nops);
|
||||
printf("A\n");
|
||||
//ncombs=ncombinations(len_ops, nops);
|
||||
ncombs=n_combs();
|
||||
printf("A\n");
|
||||
print_combs();
|
||||
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");
|
||||
set_target(target);
|
||||
//printf("len_ops=%d\nnops=%d\nops_comb=%d\n", len_ops, nops, ncombs);
|
||||
stack=new_stack(stacksize, "Main Stack", 1);
|
||||
for (i=2; i<ac; ++i) {
|
||||
val=atoi(av[i]);
|
||||
push_stack(stack, Nop, val);
|
||||
push_stack(stack, val);
|
||||
}
|
||||
|
||||
print_stack(stack, 1);
|
||||
printf("sorting stack...\n");
|
||||
mergesort_stack(stack->stack, 0, stack->last-1);
|
||||
print_stack(stack, 1);
|
||||
//print_stack(stack, 1);
|
||||
gen_stacks(stack); // printf("sorting stack...\n");
|
||||
print_stacks();
|
||||
//mergesort_stack(stack->stack, 0, stack->last-1);
|
||||
//print_stack(stack, 1);
|
||||
|
||||
i=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<ncombs; ++i) {
|
||||
opscomb=combination(ops, nops, i);
|
||||
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 (i=0; i<ntrees; ++i) {
|
||||
tree=nth_tree(i);
|
||||
for (j=0; j<ncombs; ++j) {
|
||||
comb=nth_comb(j);
|
||||
for (k=0; k<nstacks; ++k) {
|
||||
stack=nth_stack(k);
|
||||
|
||||
eval=eval_node(tree->head, 0, stack->stack, comb);
|
||||
if (eval > 0) {
|
||||
#ifdef DEBUG1
|
||||
printf("============================== %d, %d, %d\n", i, j, k);
|
||||
print_tree(tree, 0);
|
||||
print_comb(j);
|
||||
print_stack(stack, 0);
|
||||
printf("eval=%d\n", eval);
|
||||
#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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user