safePrimes.frink

Download or view safePrimes.frink in plain text format


/** This is a solver for the Rosetta Code problem
    "Safe primes and unsafe primes":

    https://rosettacode.org/wiki/Safe_primes_and_unsafe_primes
*/


safePrimes[end=undef] := select[primes[5,end], {|p| isPrime[(p-1)/2] }]
unsafePrimes[end=undef] := select[primes[2,end], {|p| p<5 or !isPrime[(p-1)/2] }]
println["First 35 safe primes:  " + first[safePrimes[], 35]]
println["Safe primes below  1,000,000: " + length[safePrimes[1_000_000]]]
println["Safe primes below 10,000,000: " + length[safePrimes[10_000_000]]]

println["First 40 unsafe primes:  " + first[unsafePrimes[], 40]]
println["Unsafe primes below  1,000,000: " + length[unsafePrimes[1_000_000]]]
println["Unsafe primes below 10,000,000: " + length[unsafePrimes[10_000_000]]]


Download or view safePrimes.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 20217 days, 23 hours, 28 minutes ago.