Emirp primes: Difference between revisions

Content added Content deleted
(adding lambdatalk task)
Line 2,181: Line 2,181:
{not :q .} }
{not :q .} }
then :n
then :n
else }}}}
else .}}}}
-> emirp
-> emirp


{def emirps
The first 20 emirp primes are :
{def emirps.loop
{S.replace \s by space in
{lambda {:n :m :a :i :j}
{S.map emirp {S.serie 2 400 1}}}
{if {or {>= :j :n} {> :i :m}}
-> 13 17 31 37 71 73 79 97 107 113 149 157 167 179 199 311 337 347 359 389
then :a with :i tests
else {emirps.loop :n :m
{if {W.equal? {emirp :i} :i}
then {A.addlast! :i :a} {+ :i 2} {+ :j 1}
else :a {+ :i 2} :j}}
}}}
{lambda {:i :n :m}
{emirps.loop :n :m {A.new} :i 0}
}}
-> emirps


{emirps 13 20 500}
The emirp primes between 7700 and 8000 are :
-> [13,17,31,37,71,73,79,97,107,113,149,157,167,179,199,311,337,347,359,389] with 391 tests
{S.replace \s by space in
{S.map emirp {S.serie 7700 8000 1}}}
-> 7717 7757 7817 7841 7867 7879 7901 7927 7949 7951 7963


{emirps 7701 11 10000}
{prime 7963}
-> [7717,7757,7817,7841,7867,7879,7901,7927,7949,7951,7963] with 7965 tests
-> 7963
{emirp 3697}
-> 3697


{emirps 948300 10 1000000}
{emirp 943849}
-> {emirps 948300 10 1000000} // stackoverflow
-> 943849 // it's an emirp

{emirp 948349}
-> 948349


</syntaxhighlight>
</syntaxhighlight>