# [seqfan] Re: Colorless integers

Charles Greathouse charles.greathouse at case.edu
Tue Feb 22 20:12:38 CET 2011

```Is there a good way to find the final cycles in Mathematica?  I know
of bad ways (say, hardcode Floyd's algorithm) and of course it could
be done manually, something like
Final[0] := {0}
Final[99] := {99, 117, 108}
Final[6732] := {6732, 6750, 6768, 6741, 6759}
Final[6642] := {6642, 6660, 6678, 6651, 6669}
. . .
Final[n_] := Final[n] = Final[nxt[n]]
but I was wondering if there's a built-in way, something like
FixedPointList[nxt, 71] but stopping at a fixed cycle rather than
fixed element.

Charles Greathouse
Analyst/Programmer
Case Western Reserve University

On Tue, Feb 22, 2011 at 12:53 PM, Harvey P. Dale <hpd1 at nyu.edu> wrote:
> Here is a simple Mathematica program to compute this sequence.  By changing the second term in the second line of the program, you can change the initial seed number.  In most cases, the resulting sequence fairly quickly devolves into a string of zeroes.  If you seed it with 71, however, it produces a sequence that, after the first five initial terms, consists of a repetitive cycle of 108, 99, 117.
>
> nxt[n_]:=Module[{tidn=Total[IntegerDigits[n]]},If[EvenQ[tidn],n+tidn, n-tidn]]
> NestList[nxt,71,100]
>
>        Best,
>
>        Harvey
>
>
> -----Original Message-----
> From: seqfan-bounces at list.seqfan.eu [mailto:seqfan-bounces at list.seqfan.eu] On Behalf Of Eric Angelini
> Sent: Tuesday, February 22, 2011 11:47 AM
> To: Sequence Fanatics Discussion list
> Subject: [seqfan] Colorless integers
>
> Hello SeqFans,
>
> (I hope this is not old hat)
>
> Let N be an integer
> Let S be the sum of N's digits
> --> make M=N+S if S is even
> --> make M=N-S if S is odd
> Iterate.
>
> Example:
>
> 71(+8)=79
>       79(+16)=95
>               95(+14)=109
>                       109(+10)=119
>                                119(-11)=108
>                                         108(-9)=99
>                                                 99(+18)=117
>                                                         117(-9)=108
> Thus 71 enters in the loop 99.117.108.99
>
> (sequitur here:
>
> Best,
> É.
>
>
> _______________________________________________
>
> Seqfan Mailing list - http://list.seqfan.eu/
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.