factor2.frink

Download or view factor2.frink in plain text format


// A (very) slightly smarter factoring algorithm.  This factors into 
// prime factors. 

n = eval[input["Enter number to factor: "]]

factor[n]

factor[x, start=2] :=
{
   m = int[sqrt[x]]

   for i = start to m
      if (x mod i) == 0
      {
         print[i + ", "]
         return factor[x/i, i]
      }
   println[x]
}


Download or view factor2.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 20139 days, 6 hours, 29 minutes ago.