[seqfan] Re: Computing sequences up to first non-distinct element: re-inventing the wheel?

Hans Havermann gladhobo at teksavvy.com
Wed Feb 15 18:14:24 CET 2012

Alonso Del Arte:

> My question is: is there a built-in Mathematica command that in this
> example would stop at the second occurrence of 4?

In[1]:= Collatz[n_Integer]:=Switch[Mod[n,2],0,n/2,1,3n+1]
In[2]:= NestWhileList[Collatz,7, Unequal, All]
Out[2]= {7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4}

More information about the SeqFan mailing list