factor2.frink

View or download 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]
}


View or download 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 17591 days, 17 hours, 47 minutes ago.