$"x=$%="@ARGV";$~=$;='( +)';while($%>>$:++){if($"=~/$~$/^$"=~/$;$/){$ |=$?=$:>2||die"prime\n";eval"print length(\$$?)".($:>++$?&&"/length(\$ $?).'*'")while$:>$?;die$/}$;=$~;$~=~s~.*~^($&\\1+)~;$~=~s;\d+;1+$&;eg}
The best thing I can say about this code is that it works. It will take a number via argv give you the prime factorization of that number... eventually. It's not very efficient. At all. I had a lot of fun writing it, but it's really bad at what it does. To give you an idea of how erratic it is, here are some benchmarks:
<Reveal this spoiler or all in this thread>
While it can distinguish primes at a reasonable rate, it takes a really long time to factor composite numbers. Particularly composite numbers made up of several small primes. Powers of 2 are the worst-case scenario.
for$b(-25..25){for$a(-50..29){$x=$a/21;$y=$b/15;print$b?chr:chr^chr ord(substr'<6C}'.1x29 .'[FDEq2?@E96Cqa6C=q924',$a)-49;$_=30;($y,$x) =(2*$x*$y+$b/15,$x*$x-$y*$y+$a/21)while$x*$x+$y*$y<9&$_++<95}$_=10}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How not to do prime factorization
by atcroft (Abbot) on Jun 30, 2015 at 16:46 UTC | |
Re: How not to do prime factorization
by QM (Parson) on Jun 30, 2015 at 15:49 UTC |
Back to
Obfuscated Code