Skip to content

Instantly share code, notes, and snippets.

@XerxesZorgon
Created December 30, 2020 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XerxesZorgon/409a0cc6364333381d38496591db8627 to your computer and use it in GitHub Desktop.
Save XerxesZorgon/409a0cc6364333381d38496591db8627 to your computer and use it in GitHub Desktop.
PARI/GP function returns unique elements of a vector, tests vectors for uniqueness
/*
Returns a vector of the unique elements of v
Input
v: vector
Output
u: Vector of unique elements of v
Example:
v = [1,1,2,2];
u = unique(V)
[1,2]
Written by: John Peach 30-Dec-2020
*/
unique(v) =
{
u = Vec(Set(v));
}
/*
Determines if all elements of vector v are unique
Input
v: vector
Output
TF: 1 if unique, 0 otherwise
Example:
v = [1,1,2,2];
isunique(v) = 0
*/
isunique(v) =
{
length(v) == length(unique(v));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment