John Cremona on Fri, 03 Nov 2023 12:42:54 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: asking for a new GP-Pari command |
On Thu, Nov 02, 2023 at 04:28:04PM -0700, American Citizen wrote:
> To all:
>
> Recently I had to remove duplicate entries from a vector.
>
> Can GP-Pari create a command which will work with both lists and vectors to
> output duplicate entries?
>
> I am aware that vecsort has flag=8 in vecsort(V,,8) and listsort has flag =
> 1 in listsort(L,1) to remove duplicates, but I need to find them, not erase
> them.
>
> Suppose v = [1,2,3,4,5,3,6]
>
> Then I would like a GP-Pari command called "duplicates(v)" to produce the
> following output.
>
> duplicates(v) = [3]
You can do that:
duplicates(v) = [x[1]|x<-matreduce(v)~,x[2]>1];
? v = [1,2,3,4,5,3,6]
? duplicates(v)
%6 = [3]
Cheers,
Bill