MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re:NestWhile

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23656] Re: Re:NestWhile
  • From: "Paul R. Wellin" <wellin at wolfram.com>
  • Date: Sun, 28 May 2000 23:09:07 -0400 (EDT)
  • References: <8eg6sc$hd7@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Although slightly tangential to the initial thread here, I thought those who
are interested in Keith numbers/sequences may like to search for them. Some
time ago, I wrote a short program to do this. The first function KeithQ
determines whether a number n is a Keith number in base b (base 10 by
default, but it is interesting to look in other bases). The second simple
function SearchKeith picks out all Keith numbers in a specified range.

KeithQ[n_, b_:10] := Module[{t = IntegerDigits[n, b]},
    While[Last[t] < n, t = Rest[Append[t, Plus @@ t]]];
    Last[t] == n]

SearchKeith[a_, b_] := Select[Range[a, b], KeithQ]


Here are all the Keith numbers between 100 and 2000:

In[3]:= SearchKeith[100, 2000] // Timing
Out[3]= {2.58 Second, {197, 742, 1104, 1537}}


Using the function below, you can check 742 for example:

In[4]:= V3KeithSequence[742]
Out[4]= {7, 4, 2, 13, 19, 34, 66, 119, 219, 404, 742}


Paul Wellin
Wolfram Research, Inc.
wellin at wolfram.com


"Alan W.Hopper" <awhopper at hermes.net.au> wrote in message
news:8eg6sc$hd7 at smc.vnet.net...
>
> 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
>
>
>



  • Prev by Date: how embed fonts with emmathfnt?
  • Next by Date: FindMinimum of a compiled function??
  • Previous by thread: how embed fonts with emmathfnt?
  • Next by thread: FindMinimum of a compiled function??