2
$\begingroup$

Given

t2 = {{1, 5}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2, 5}, {3, 1}, {3, 
2}, {3, 3}};

I can get coprime pairs by

Pick[#, CoprimeQ @@@ #] &@t2

or by

Select[t2, CoprimeQ[#[[1]], #[[2]]] &]

But I want to use Select in a more elegant way. Any ideas?

$\endgroup$
4
  • 5
    $\begingroup$ Why do you need it to be 'elegant'? What you have is already fast and readable. I would write Select[t2, CoprimeQ@@#&] if I wanted to be more terse. $\endgroup$
    – flinty
    Jun 5 '20 at 14:30
  • $\begingroup$ Thank you! I am still learning and try to understand using pure functions. $\endgroup$
    – user57467
    Jun 5 '20 at 14:34
  • 2
    $\begingroup$ Or a non-pure function method: Pick[t2, CoprimeQ @@@ t2] $\endgroup$ Jun 5 '20 at 15:08
  • 1
    $\begingroup$ Or Pick[#,CoprimeQ@@Transpose@#]&[t2] $\endgroup$
    – user1066
    Jun 5 '20 at 15:52
2
$\begingroup$
Select[Apply @ CoprimeQ] @ t2
{{1, 5}, {2, 1}, {2, 3}, {2, 5}, {3, 1}, {3, 2}}

Also

Select[CoprimeQ @@ # &] @ t2
{{1, 5}, {2, 1}, {2, 3}, {2, 5}, {3, 1}, {3, 2}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.