On Aug 4, 2:59 pm, Offray Vladimir Luna Cárdenas
<[email protected]> wrote:
>
> Thanks also. Works on Firefox on an arch linux over intel centrino. This
> could be a project for an interested student.
>

You can get a solution with the following short Sage code:

def weight(v):
    return sum([1 for i in v if i==1])

def solve_lights(n):
    g = graphs.Grid2dGraph(n,n)
    M = g.adjacency_matrix().base_extend(GF(2))
    M = M+diagonal_matrix(GF(2),[1 for i in range(M.nrows())])
    v = vector(GF(2),[1 for i in range(M.nrows())])
    NS = M.kernel()
    sol = M\v
    print 'a solution:'
    print matrix(n,list(sol))
    print 'computing minimal solution'
    min_w = weight(sol)
    for i in NS:
        new_sol = i + sol
        new_weight = weight(new_sol)
        if(new_weight < min_w):
            sol = new_sol
            min_w = new_weight
    min_sol=matrix(n,list(sol))
    return min_sol

The student can try to explain why this works :)

Or they can try to play the hexagonal version

http://www.math.uiuc.edu/~rkirov2/hexout/

Rado
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
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-edu?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to