Project euler no. 3

Someone Something fordhaivat at gmail.com
Sat Sep 12 18:04:20 CEST 2009


Anyone?

On Sat, Sep 12, 2009 at 11:46 AM, Someone Something <fordhaivat at gmail.com>wrote:

> But, I'm returning true or false right?
>
> On Sat, Sep 12, 2009 at 11:32 AM, MRAB <python at mrabarnett.plus.com> wrote:
>
>> Someone Something wrote:
>>
>>> Project euler (in case you don't know: projecteuler.net <
>>> http://projecteuler.net>)
>>>
>>> I'm trying to do the third one and here's my current code:
>>>
>>>  1 def checkPrime (x):
>>>  2     factors=2;
>>>  3     while factors<=x:
>>>  4         if x==factors:
>>>  5             return True;
>>>  6         elif x%factors==0:
>>>  7             return False;
>>>  8         elif x%factors!=0:
>>>  9             factors=factors+1;
>>>
>>
>> You're not returning 'factors', so the function will return None.
>>
>>
>>   10
>>>  11 factorl=[];
>>>  12 factors=600851475142;
>>>  13
>>>  14 while factors != 1:
>>>  15     if 600851475143%factors==0:
>>>  16         if checkPrime(factors)==True:
>>>  17             print factors;
>>>  18         else:
>>>  19             factors=factors-1;
>>>  20
>>>  21     else:
>>>  22         factors=factors-1;
>>>  23
>>>
>>> And it just gets frozen when I run it. I put a
>>>
>>> print "Loop completed"
>>>
>>> in one of the loops and it showed up just fine. So, there are two
>>> possibilities:
>>> 1. Its looping in the trillions and taking a while
>>> 2. I have a forever loop somewhere
>>>
>>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090912/72472e17/attachment.html>


More information about the Python-list mailing list