amicableNumbers.frink

View or download 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 = 2
seen = new set

do
{
   if seen.contains[n]
   {
      n = n + 1
      next
   }
   sum = sum[allFactors[n, true, false, false]]
   if sum[allFactors[sum, true, false, false]] == n
   {
      println["$n, $sum"]
      seen.put[sum]
   }
   n = n + 1
} while true


View or download 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 18233 days, 19 hours, 38 minutes ago.