Suppression of "6 numbers" limit. New option to choose tree type.
This commit is contained in:
17
oper.c
17
oper.c
@@ -4,7 +4,7 @@
|
||||
#include <malloc.h>
|
||||
#include "lceb.h"
|
||||
|
||||
static char *combs[1024]; /* should be dynamic */
|
||||
static char **combs;
|
||||
static int ncombs=0;
|
||||
|
||||
void print_comb(n)
|
||||
@@ -59,19 +59,23 @@ static char *combine(ops, len, n)
|
||||
void gen_combinations(nops)
|
||||
int nops;
|
||||
{
|
||||
char *ops="+-*/";
|
||||
char *ops="/-*+";
|
||||
int i, n_combs;
|
||||
int len_ops=strlen(ops);
|
||||
# ifdef DEBUG_OPER
|
||||
printf("gen_combinations(%d)\n", nops);
|
||||
# endif
|
||||
n_combs=n_combine(len_ops, nops);
|
||||
//printf("gen: n=%d\n", n_combs);
|
||||
# ifdef DEBUG_MEM
|
||||
printf("allocating %d operators combinations\n", n_combs);
|
||||
# endif
|
||||
combs=malloc(sizeof (char*)*n_combs);
|
||||
for (i=0; i<n_combs; ++i) {
|
||||
combs[ncombs]=strdup(combine(ops, nops, i));
|
||||
ncombs++;
|
||||
}
|
||||
}
|
||||
|
||||
int n_combs()
|
||||
{
|
||||
return ncombs;
|
||||
@@ -87,12 +91,17 @@ int main(ac, av)
|
||||
int ac;
|
||||
char **av;
|
||||
{
|
||||
char *ops="+-*/", *p;
|
||||
char *ops="/-+*", *p;
|
||||
int len_ops=strlen(ops);
|
||||
int i, nops, ncombs;
|
||||
|
||||
if (ac!=2) {
|
||||
fprintf(stderr, "usage: %s nops\n", *av);
|
||||
exit (1);
|
||||
}
|
||||
nops=atoi(*(av+1));
|
||||
ncombs=n_combine(len_ops, nops);
|
||||
combs=malloc(sizeof (char*)*ncombs);
|
||||
printf("# operators combinations : %d\nlist = ", ncombs);
|
||||
for (i=0; i<ncombs; ++i) {
|
||||
p=combine(ops, nops, i);
|
||||
|
Reference in New Issue
Block a user