initial version
This commit is contained in:
68
lceb.c
Normal file
68
lceb.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <malloc.h>
|
||||
#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;
|
||||
|
||||
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; i<ac; ++i) {
|
||||
val=atoi(av[i]);
|
||||
push_stack(stack, Nop, val);
|
||||
}
|
||||
|
||||
print_stack(stack, 1);
|
||||
printf("sorting stack...\n");
|
||||
mergesort_stack(stack->stack, 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<ncombs; ++i) {
|
||||
opscomb=combination(ops, nops, i);
|
||||
//printf("OPS=%s\n", opscomb);
|
||||
//set_ops_stack(stack, opscomb);
|
||||
//print_stack(stack, 0);
|
||||
//res=eval_stack(stack);
|
||||
//printf("EVAL=%d\n", res);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
exit(0);
|
||||
}
|
Reference in New Issue
Block a user