Prime Factors Golf
Liyang Hu
liyang at nerv.cx
Wed Mar 27 20:15:07 CST 2002
On Wed, Mar 27, 2002 at 09:07:17PM +0000, Smylers wrote:
> An algorithm for finding prime factors occurred to be while lying
> in bed this morning.
> #! /usr/bin/perl
> $%=pop;$/=2;$%%$/&&$/++or$%/=$/,push@%,$/while$%>1;@%or@%=$%;$,=' x ';print@%
^^^^^^^^^^
Why do you need that bit? I wouldn't bother, at least not by my
definition of `factorisation', or what a factor is.
Also, if you're willing to dispense with the spaces between the
factors, you can shave off a further, not 2, but 4 strokes: (Thanks
to Tony for that one.)
> $%=pop;$/=2;$%%$/&&$/++or$%/=$/,push@%,$/while$%>1;$,=x;print@%
63 strokes. ^_^
/Liyang
--
.--{ Liyang HU }--{ http://nerv.cx/ }--{ Caius at Cam }--{ ICQ: 39391385 }--.
| %% Q: Ever heard of .cshrc? %% A: That's a city in Bosnia. Right? %%%% |
More information about the Belfast-pm
mailing list