amicableNumbers.frink

Download or view amicableNumbers.frink in plain text format


/** This program uses a simple brute-force method to find "amicable numbers",
    that is, pairs of numbers in which the sum of the proper divisors of each
    number (including 1 but excluding the number itself) equals the other
    number. */

n = 1
seen = new set

do
{
   n = n + 1
   if seen.contains[n]
      next

   sum = sum[allFactors[n, true, false, false]]
   if /*sum != n and */ sum[allFactors[sum, true, false, false]] == n
   {
      println["$n, $sum"]
      seen.put[sum]
   }
} while true



Download or view amicableNumbers.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 19967 days, 14 hours, 32 minutes ago.