Re:NestWhile
- To: mathgroup at smc.vnet.net
- Subject: [mg23265] Re:NestWhile
- From: "Alan W.Hopper" <awhopper at hermes.net.au>
- Date: Sat, 29 Apr 2000 22:05:07 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Dear mathgroup ,
Concerning my query before Easter, about a version 3 equivalent to
NestWhile.
Thanks to Hartmut Wolf, Daniel Reeves, Andrzej Kozlowski, and
Jens-Peer Kuska
for their solutions.
And I received an e-mail from Eric Bynum of Wolfram Technical Support,
with code
which appropriately utilizes both Nest and While. Thanks also, Eric.
Here is Eric's Mathematica 3 Keith Sequence solution ;
In[1]:=
V3KeithSequence[n_Integer?Positive] :=
Module[{d = IntegerDigits[n], l, counter, lis},
l = Length[d];
counter = 1;
While[Nest[Append[#, Plus @@ Take[#, -l]] &, d, counter][[-1]] <
n,
counter++;
lis = Nest[Append[#, Plus @@ Take[#, -l]] &, d, counter]];
lis
]
In[5]:=
V3KeithSequence[197]
Out[5]=
{1, 9, 7, 17, 33, 57, 107, 197}
Where as before, 1+9+7=17, 9+7+17=33, etc., ending again with 197.
Alan Hopper
awhopper at hermes.net.au