On Sun, Aug 12, 2012 at 10:49 AM, eryksun <eryk...@gmail.com> wrote: > On Sun, Aug 12, 2012 at 10:58 AM, Dave Angel <d...@davea.name> wrote:
> Good catch in Kent Johnson's code. Maybe he'll search for his name and > find this. It should be `r = r // factor`. The fault was probably mine. Kent wrote this in 2004, in Python 2.x. When I moved to 3.x I converted the function to 3.x, but missed that one. See Kent's Tutor post archived at <http://mail.python.org/pipermail/tutor/2004-October/032437.html> I've had an amazing amount of help today. I haven't had time to attend to all of it yet, but thought I'd get this out. Since posting last I've found that my script (<pickle_attempt_for_web2.py>) that I thought was perfect (except for lines 74-78), isn't. Obvious errors in the dictionary/pickle, such as even prime factors! I'm hoping that correcting Kent's function will stop the sort of errors I've found. And I've found an obvious test: The product of an integers prime factors must equal the integer itself. And of course the factors must be tested for primacy(?)/prime numberhood(?), which is quickly done with gmpy2's is_prime(). I just now checked one of the erroneous items that had an even prime factor: n = 279918016070854658 a random 18-digit integer the factors of 279,918,016,070,854,658 are [2, 7, 41, 487662048903928] After correcting Kent's function, I correctly get > 279918016070854658 the factors of 279,918,016,070,854,658 are [2, 7, 3011, 6640366657277] >>>487662048903928*2*7*41 279918016070854672 >>>2*7*3011*6640366657277 279918016070854658 >>>is_prime(3011) True >>>is_prime(6640366657277) True I also just pasted the 3rd version of my script, pickle_attempt_for_web3.py, at <http://pastebin.com/Ec2ru9jW>. Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor