Script Library: 1238 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
View scriptLicenseDownload documentation as: HTML or editable
Download scriptHistoryOther scripts by: sunanda

Documentation for: oneliner-prime-factors.r

Shorter version

The version listed was exactly on the 132 character limit for the original one-liner "competition" at

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: cp[]until[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).

0.1 Differences:

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!?