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

RGWv rgwv at rgwv.com
Wed Feb 15 22:04:04 CET 2012


I think that MemberQ is the function you are looking for.

-----Original Message----- 
From: Alonso Del Arte
Sent: Wednesday, February 15, 2012 12:01 PM
To: Sequence Fanatics Discussion list
Subject: [seqfan] Computing sequences up to first non-distinct element: 
re-inventing the wheel?

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>

_______________________________________________

Seqfan Mailing list - http://list.seqfan.eu/ 




More information about the SeqFan mailing list