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

Alonso Del Arte alonso.delarte at gmail.com
Wed Feb 15 18:01:34 CET 2012


I started writing a function in Mathematica that at the addition of
each element to a list tests whether that element has already shown up
on the list before and stops when that occurs. But it really felt like
I was reinventing the wheel, though I don't know what would be the
built-in command that does this.

A good example of this are Collatz sequences, though conjecturally you
just have to test for the occurrence of 1 to know when to stop, e.g.,

7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1,
4, 2, 1, 4, ... (no need to keep going).

FixedPointList doesn't work for this purpose, unless you hard-code
f(1) = 1 (I think I have done that for one or two programs in the
OEIS).

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

Al

-- 
Alonso del Arte
Author at SmashWords.com<https://www.smashwords.com/profile/view/AlonsoDelarte>
Musician at ReverbNation.com <http://www.reverbnation.com/alonsodelarte>



More information about the SeqFan mailing list