What is the shortest way, by character count, to find prime factors in any number?
Example Input: 1806046
Example Output: 2x11x11x17x439
What is the shortest way, by character count, to find prime factors in any number?
Example Input: 1806046
Example Output: 2x11x11x17x439
Euphoria: 106 characters
Mathematica (15 chars including brackets):
Example:
Python recursive solution
99 characters (including spaces) 87 characters (without spaces)
Update: A completely recursive version
Both versions are prone to stack overflows for all but the smallest of inputs.
GNU bc, 47 chars, including collecting input (need the GNU extensions for
print
,else
andread
):If you really want the x characters in the output, it's 64 chars:
Also, note that using bc allows this to process numbers of arbitrary length.
Best Perl answer yet - 70 characters, and no extra modules (unless you count special features of 5.10):
Doesn't work for 1 or 0, but works fine for everything else. If you don't like using
say
, or are using an earlier version of Perl, here's an 81 character version:Ruby
39B71B (via STDIN)