More digital silliness
Bob Hearn
seqfan at hearn.to
Wed Jan 9 21:43:52 CET 2008
The somsto[] function is 1.) buggy and 2.) too complicated.
Using
sumsto[{}, _] = False;
sumsto[{x_}, n_] := x === n;
sumsto[{___, n_, ___}, n_] = True;
sumsto[lst_, n_] := False /; n < Min[lst];
sumsto[{a_, r__}, n_] := sumsto[{r}, n - a] || sumsto[{r}, n];
and an other general algorithm (after a valuable hint from Franklin T.
Adams-Watters), I get still the same result.
Peter
petsie at dordos.net schrieb:
> Maybe I made an error when coding this problem...
> I find the start of this sequence until 162 but no more elements up to 10000.
> Is this correct?
>
> Peter
>
> Mathematica code follows:
>
> sumsto[{}, _] = False;
> sumsto[{___, n_, ___}, n_] = True;
> sumsto[{a_, b_, r___}, n_] := If[a + b === n, True,
> If[a + b < n, sumsto[{b, r}, n - a] || sumsto[{a, r}, n - b] ||
> sumsto[{r}, n - a - b] || sumsto[{r}, n],
> False]];
More information about the SeqFan
mailing list