define clean [ matrix m ] matrix m2 = matrix_of_zeroes(m.dimensions) for point p (m.allpoints) if m.value(p) and not m2.value(p) if not try_solution(m, m2, [ p ]) m.value(p) = 0 # by now m and m2 are the same define try_solution [ matrix m, matrix m2, array of points plist ] int row = first_row_not_already_tried(plist) if not defined row # all rows tried, so this is a solution for point p (@plist) m2.value(p) = 1 return true for int col (grep column_not_in_plist(plist, $_), m.allcols) point p = point_at(row, col) if m.value(p) if try_solution(m, m2, [ @plist, p ]) return true return false