board_width  = 5
board_height = 5
n = board_width * board_height

# Set up the matrix of button pushes
A = [[0]*n for i in xrange(n)]
for i in xrange(board_width):
  for j in xrange(board_height):
    idx = i + j * board_width
    A[idx][idx] = 1
    if i > 0:                A[idx - 1][idx] = 1
    if i < board_width - 1:  A[idx + 1][idx] = 1
    if j > 0:                A[idx - board_width][idx] = 1
    if j < board_height - 1: A[idx + board_width][idx] = 1

# A couple helpers
def add_rows(A, i, j):  return [(A[i][k] + A[j][k])%2 for k in xrange(n)]
def swap_rows(A, i, j): A[i], A[j] = A[j], A[i]

# The input state to solve
state = map(int, '1011100111110001100111010')

# Solve via something like Gaussian Elimination
for col in xrange(n):
  # find the first row with a 1 in this column
  for row in xrange(col,n):
    if A[row][col] == 1:
      swap_rows(A, row, col)
      swap_rows(state, row, col)
      for other in xrange(n):
        if other != col and A[other][col] == 1:
          A[other] = add_rows(A, other, col)
          state[other] = state[other] ^ state[col]

# Print out the buttons to be pressed
for j in xrange(board_height):
  print ''.join(map(str,state[j*board_width:(j+1)*board_width]))

