diff --git a/eval.c b/eval.c index e3a7ec6..c2d0997 100644 --- a/eval.c +++ b/eval.c @@ -63,15 +63,20 @@ int eval_node(node, depth, pvals, pops, ncalcs) res=val1+val2; break; case Mul: - res=val1*val2; + if (val1 > 1 && val2 > 1) /* we avoid "x*1" */ + res=val1*val2; break; case Sub: if (val1 > val2) res=val1-val2; + if (res == val2) /* we already got this value in tree */ + res=-1; break; case Div: - if (val1 > val2 && (val1 % val2 == 0)) + if (val1 >= val2 && val2 != 1 && (val1 % val2 == 0)) res=val1/val2; + if (res == val2) /* we already got this value in tree */ + res=-1; break; case Nop: case End: