[Tutor] why?

Robert William Hanks astroultraman at gmail.com
Thu May 29 10:01:42 CEST 2008


hi, i do not need a fancy elegant code, know this one is ugly and take to
much time(i will for now use ctrl+c to break)
my problem is that the result are wrong, just test one of the reults printed
by this code, and you will see tha the results are wrong.
Maybe something i do not understand is happenig wen python round the the
cubed root. is this code wrong?

On 5/29/08, Kent Johnson <kent37 at tds.net> wrote:

> On Wed, May 28, 2008 at 8:43 PM, Robert William Hanks
> <astroultraman at gmail.com> wrote:
> >
> >  Need ti find out whem a number o this form i**3+j**3+1 is acube.
> >  tryed a simple brute force code but, why this not work?
> >
> > def iscube(n):
> >     cubed_root = n**(1/3.0)
> >     if round(cubed_root)**3 == n:
> >         return True
> >     else:
> >         return False
> >
> > for i in range(1,10000000):
> >     for j in range(1,10000000):
> >          soma= i**3 +j**3 +1
> >          if isCube(soma):
> >              print i
> >              print j
> >              print soma
>
> Let's see. The inner loop will run 10000000 * 10000000 =
> 100000000000000 times. That's a pretty big number. Suppose each
> iteration of the loop takes 1 microsecond. (That seems optimistic but
> not too much - on my computer iscube(27) takes about 1.3
> microseconds.) Then the entire program will complete in 10000000 *
> 10000000 / 1000000 / 60 / 60 / 24 / 365 = 3 years. Other than that it
> look OK to me...
>
> Looks like you need either a better algorithm or a faster computer!
>
> Kent
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080529/4dcbd0ff/attachment-0001.htm>


More information about the Tutor mailing list