Download or view strangePrimes.frink in plain text format
// Solver for Rosetta Code problem:
// https://rosettacode.org/wiki/Strange_unique_prime_triplets
//
// This is a good test of the multifor statement where one value relies on
// values to its left, including torture-testing the cases where a lot of
// backtracking is required. This did not work right until 2025-04-12.
strangePrimes[max, print=false] :=
{
count = 0
multifor [n,m,p] = [primes[2,max], primes[n+1,max], primes[m+1,max]]
{
sum = n + m + p
if isPrime[sum]
{
count = count + 1
if print
println["$n + $m + $p = $sum"]
}
}
println["Found $count unique strange prime triplets up to $max"]
}
strangePrimes[30, true]
strangePrimes[1000, false]
Download or view strangePrimes.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, eliasen@mindspring.com