4
$\begingroup$

I have the following data

sol={{2063, 853}, {2066, 855}, {2069, 857}, {2072, 859}}

I can find prime-pairs by

Select[sol, PrimeQ[#[[1]]] && PrimeQ[#[[2]]] &]

yielding

{{2063, 853}, {2069, 857}}

Are there more elegant ways using Cases (or others)?

$\endgroup$
3
  • $\begingroup$ pq[v_]:=And@@Map[PrimeQ,v]; Select[sol,pq] ? $\endgroup$ – Bill Mar 22 '20 at 13:14
  • 9
    $\begingroup$ sol // Select[AllTrue[PrimeQ]] $\endgroup$ – swish Mar 22 '20 at 13:15
  • 3
    $\begingroup$ Akku's solution will strictly select pairs of primes, while kglr's solution will pick out lists of primes of any length. $\endgroup$ – J. M.'s torpor Mar 23 '20 at 10:39
9
$\begingroup$
Cases[{__?PrimeQ}] @ sol

{{2063, 853}, {2069, 857}}

$\endgroup$
6
$\begingroup$
Cases[sol, {_?PrimeQ, _?PrimeQ}]

(*   {{2063, 853}, {2069, 857}}   *)
$\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.