----- Original Message ----- 
From: "Timothy Clemans" <[EMAIL PROTECTED]>
>
> def magicsquare_normal_odd(n):
>    r"""
>    Generates nth odd normal magic square for n greater than 1 using
> de la Loubere's method.
>
>    EXAMPLES:
>        sage: magicsquare_normal_odd(1)
>        [8 1 6]
>        [3 5 7]
>        [4 9 2]
>        sage: magicsquare_normal_odd(2)
>        [17 24  1  8 15]
>        [23  5  7 14 16]
>        [ 4  6 13 20 22]
>        [10 12 19 21  3]
>        [11 18 25  2  9]

<--skip-->

That can be done in Python in one line,

def Siamese_magic_square(n):
    return [[(i+j+(n+1)/2)%n*n+(i+2*j+1)%n+1 for j in range(n)]
       for i in range(n)]

For example,

Siamese_magic_square(3)
[[8, 1, 6], [3, 5, 7], [4, 9, 2]]

Siamese_magic_square(5)
[[17, 24, 1, 8, 15], [23, 5, 7, 14, 16], [4, 6, 13, 20, 22], [10, 12, 19, 
21, 3], [11, 18, 25, 2, 9]]

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