On Sat, Jan 31, 2009 at 11:26 AM, mabshoff
<[email protected]> wrote:
>
>
>
> On Jan 31, 11:17 am, William Stein <[email protected]> wrote:
>> On Sat, Jan 31, 2009 at 11:15 AM, Rolandb <[email protected]> wrote:
>>
>> > Hi,
>>
>> > I received first a MemoryError, and later on Sage reported:
>>
>> That means that Sage ran out of memory.  It's not a bug -- it's just a
>> limitation of your computer.
>
> srange() builds a list in memory, so using an iterator will make that
> code use less memory.

Good idea.  His an iterator version of the code:

uitkomst1=[]
uitkomst2=[]
eind=int((10^9+2)/(2*sqrt(3)))
print eind
for y in (1..eind):
 test1=is_square(3*y^2+1,True)
 test2=is_square(48*y^2+1,True)
 if test1[0] and test1[1]%3==2: uitkomst1.append((y,(2*test1[1]-1)/3))
 if test2[0] and test2[1]%3==1: uitkomst2.append((y,(2*test2[1]+1)/3))
print uitkomst1
een=sum(3*x-1 for (y,x) in uitkomst1 if 3*x-1<10^9)
print uitkomst2
twee=sum(3*x+1 for (y,x) in uitkomst2 if 3*x+1<10^9)
print een+twee

It prints

288675135
... and I got bored waiting for the rest...

William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to