I was trying to write a general program to check The 17x17 problem SOLVED!, 4-coloring of a17x17 grid with no monochromatic rectangles. Solution link: 17.txt.
This is what I wrote:
from itertools import product
def is_solution(myfile,m,n):
""" m-lines, n-columns """
grid = [c.strip() for c in line.split(',')] for line in open(myfile).readlines()]
for x0,y0 in product(xrange(m),xrange(n)):
start = grid[x0][y0]
for x in xrange(x0+1,m):
if grid[x][y0] == start:
for y in xrange(y0+1,n):
if grid[x0][y] == start == grid[x][y]:
return False
return True
print is_solution('17.txt',17,17)
Is there a more readable, concise or efficient way (in that order of priority) to write this? Maybe a different approach with different data structures... Since i am learning Python at the moment, any advice is very welcome.