Alec is your code suppose to be able to generate any nth normal magic square?

sage: print magicsquare_normal(4)
[ 9 15  1  7]
[14  4  6 12]
[ 3  5 11 13]
[ 8 10 16  2]
sage: print [sum(magicsquare_normal(4)[i]) for i in range(4)]
[32, 36, 32, 36]
sage: print magicsquare_normal(6)
[19 27 35  1  9 17]
[26 34  6  8 16 24]
[33  5  7 15 23 25]
[ 4 12 14 22 30 32]
[11 13 21 29 31  3]
[18 20 28 36  2 10]
sage: print [sum(magicsquare_normal(6)[i]) for i in range(6)]
[108, 114, 108, 114, 108, 114]

On 2/3/07, Timothy Clemans <[EMAIL PROTECTED]> wrote:
> Well I think its game over for me on this one. I might work with my
> code some more just to learn more about this stuff. Stein please add
> Alec's magicsquare_normal function to SAGE after more optimizing. My
> math teacher might use SAGE if she gives a lecture on magic squares.
> Now if the notebook was nearly as fast as the command line I would be
> very happy.
>
> On 2/3/07, Timothy Clemans <[EMAIL PROTECTED]> wrote:
> > I'm very concerned about speed. Thank you for sharing your code.
> >
> > On 2/3/07, Alec Mihailovs <[EMAIL PROTECTED]> wrote:
> > >
> > > From: "Timothy Clemans" <[EMAIL PROTECTED]>
> > > >
> > > > Wow! Now thats cool. I'm going to time test them. Thanks
> > >
> > > I had some trouble with copying and pasting your procedure in SAGE 
> > > (because
> > > I use it in Windows through cygwin and rxvt with Unix line endings and my
> > > email has Windows line endings and convert it to Unix by creating a text
> > > file and then using dos2unix on it seemed to be too much trouble). So I
> > > modified your procedure to plain Python by changing ^ to ** in 2 places 
> > > and
> > > changing the end line in it to return square.
> > >
> > > After that I did timing in IDLE using the print_timing decorator from
> > > http://www.daniweb.com/code/snippet368.html .
> > >
> > > It appears that Siamese_magic_square is about 4-5 times faster than
> > > magicsquare_normal_odd.
> > >
> > > Actually, if the time is important, it can be made even faster by changing
> > > the j range (that reduces the number of operations). In SAGE form that 
> > > looks
> > > like
> > >
> > > def Siamese_magic_square(n):
> > >     return matrix([[j%n*n+(j+j-i)%n+1
> > >         for j in range(i+(1-n)/2,i+(n+1)/2)] for i in range(n)])
> > >
> > > That makes it about 6-7 times faster than magicsquare_normal_odd (in IDLE,
> > > without matrix - I didn't test that in SAGE and I don't know how the 
> > > matrix
> > > construction works there - in particular, whether adding the size of the
> > > matrix would make it faster.)
> > >
> > > Alec Mihailovs
> > > http://mihailovs.com/Alec/
> > >
> > >
> > >
> > > > > >
> > >
> >
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
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://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to