C
Charles Zheng
There is an algorithm that tests primes with a polynomial running time:
http://fatphil.org/maths/AKS/
Has anyone coded it in Ruby?
http://fatphil.org/maths/AKS/
Has anyone coded it in Ruby?
Well, I'm gonna guess that if anyone has, they would post it on that website.
I can't get to the original paper (server's offline, file removed?),
I'll try my hand at it eventually, but I don't think I could do it in
an afternoon.
Charles said:There is an algorithm that tests primes with a polynomial running time:
http://fatphil.org/maths/AKS/
Has anyone coded it in Ruby?
Michael said:Hello Charles:
Here is an example of that algorithm demonstrated via a method which
extends the Fixnum class.
class Fixnum
def is_prime?
((("1" * self) =~ /^1$|^(11+?)\1+$/) == nil)
end
end ...
The turnaround time on solving is almost instantaneous for this
algorithm until the numbers start gets really big (i.e. like the 123457
above). I don't know if this matches the criteria for "polynomial
running time" but thought you might find this interesting if you didn't
know about it.
Michael
That is pretty cool. It is not of polynomial running time since it
tries
to factor the number brute-force, but that is a very nifty reg EXP
trick.
That is pretty cool. It is not of polynomial running time since it tries
to factor the number brute-force, but that is a very nifty reg EXP
trick.
Charles, take a peak at the mathn library for your greatest prime factor...
require 'mathn'
n = 12345654321
p n.prime_division.last[0]
That is pretty cool. It is not of polynomial running time since it tries
to factor the number brute-force, but that is a very nifty reg EXP
trick.
Charles, take a peak at the mathn library for your greatest prime factor...
require 'mathn'
n = 12345654321
p n.prime_division.last[0]
Charles, take a peak at the mathn library for your greatest prime factor...
require 'mathn'
n = 12345654321
p n.prime_division.last[0]
Funny, I tried this with the same number with a 1 attached to the end
(123456543211). It took about 20 minutes, but determined it was prime
(i.e. returned [123456543211, 1]) which means 123456543211 to the
power of 1. Coincidence
Todd
Yes, try Miller-Rabin or some other test like it. They're nothttp://snippets.dzone.com/posts/show/4636
You may check the outcome with primegen, http://cr.yp.to/primegen.html
time -p primes 123456543211 123456543211 # done in well under a second
Cheers,
j. k.
Charles said:There is an algorithm that tests primes with a polynomial running time:
http://fatphil.org/maths/AKS/
Has anyone coded it in Ruby?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.