Given a list tuples Tuples[Range[10],2]
I'd like to select the ones that match a certain criteria. Namely that for every pair {x ,y}
, GCD[y, x] == 1
and Mod[x, y] != 2
I've tried the following.
Select[Tuples[Range[10], 2], Function[{x, y}, GCD[x, y] == 1 && Mod[x, y] != 2]]
But, I understand I'd have to supply the function with a symbol (and not a list).
How could I filter out that list of tuples?
Tuples[Range[10], 2] // Select[GCD[#[[1]], #[[2]]] == 1 && Mod[#[[1]], #[[2]]] != 2 &]
$\endgroup$&
at the end. It didn't work. Said#1
had no attributes or something akin to that. Why does it work with the&
at the end? $\endgroup$Function
. When using a pure function with formal parameters (e.g.,#1
), the&
is needed to mark the end of the pure function's body. $\endgroup$Select[Tuples[Range[10],2],Apply[Function[{x,y},GCD[x,y]==1&&Mod[x,y]!=2]]]
$\endgroup$