almostPrime.frink

Download or view almostPrime.frink in plain text format

/*
   Solver for "almost prime" entry on Rosetta Code:

   A k-Almost-prime is a natural number n that is the product of k (possibly
   identical) primes. So, for example, 1-almost-primes, where k = 1, are the
   prime numbers themselves; 2-almost-primes are the semiprimes.

   The task is to write a function/method/subroutine/... that generates
   k-almost primes and use it to create a table here of the first ten members
   of k-Almost primes for 1 < = K < = 5.

   http://rosettacode.org/wiki/Almost_prime
*/


for k = 1 to 5
{
   n=2
   count = 0
   print["k=$k:"]
   do
   {
      if length[factorFlat[n]] == k
      {
         print[" $n"]
         count = count + 1
      }
      n = n + 1
   } while count < 10

   println[]
}


Download or view almostPrime.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 19966 days, 23 hours, 8 minutes ago.