Menu

[r376]: / XEMIRP.MPL  Maximize  Restore  History

Download this file

31 lines (23 with data), 517 Bytes

/*
  EMIRP PRIMES - MPL VERSION
  HTTPS://ROSETTACODE.ORG/WIKI/EMIRP_PRIMES#C
*/

##LIBHDR

IS.PRIME(N;P) [
  ==(N\2) || ==(N\3) ? =0;
  P=1; *P<N @ ==(N\P+=4) || ==(N\P+=2) ? =0;
  1
]

REVERSE(N;R) [
  R=0; N @ [ R=R*10+N\10; N/=10 ]; R
]

IS.EMIRP(N;R) [
  R = REVERSE(N); R<>N && IS.PRIME(N) && IS.PRIME(R)
]

.(;X,C) [
  X=11; C=0; C<20 @ [ IS.EMIRP(X) ? [ WRITEF(" %N",X); ++C]; X+=2 ];
  NEWLINE();
  X=7701; X<8000 @ [ IS.EMIRP(X) ? WRITEF(" %N",X); X+=2 ];
  NEWLINE();
  0
]

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.