|View script||License||Download documentation as: HTML or editable|
|Download script||History||Other scripts by: sunanda|
Script Library: 1223 scripts
Documentation for: oneliner-prime-factors.r
The version listed was exactly on the 132 character limit for the original one-liner "competition" at REBOL.com.
It is possible to go much shorter, but at the cost of running much, much slower. Here's the shortest I've managed: 117 characters:
f: func[n][m: 2 w: :append a: cpuntil[either n // m = 0[n: n / m w a m][m: m + 1]if m ** 2 > n[w a n n: 1]n = 1]a]
(if you cut'n'paste that from this documentation, you may find the greater-than sign has been replaced with its named entity).
1/ removed 's variable....We're now running at half the speed as it checks for every integer from 1 to sqrt(n). With 's defined, we check 2, 3, 5, 7 etc -- just 2 and the odd numbers.
2/ replaced "1. * m * m" with m "** 2"
3/ replaced "copy" with "cp" (thanks to Volker for showing me that built-in synonym).
Can anyone break the 100 character barrier for this function!?