Prime Factors Golf

Smylers Belfast-PM at stripey.com
Wed Mar 27 15:07:17 CST 2002


An algorithm for finding prime factors occurred to be while lying in bed
this morning.  I seem to've mislaid the mail suggesting this as a golf
challenge, but this what I've come up with for 77:

  #! /usr/bin/perl
  $%=pop;$/=2;$%%$/&&$/++or$%/=$/,push@%,$/while$%>1;@%or@%=$%;$,=' x ';print@%

Sample use:

  $ ./factors 84
  2 x 2 x 3 x 7

Smylers




More information about the Belfast-pm mailing list