sudoku solution verifier – python

write a sudoku solution verifier in python.

that is, given a list of lists, representing a solution to an nxn sudoku puzzle, verify that the solution is a correct sudoku solution:

fn ([[1,2],[2,1]]) # True
fn ([[1,3],[2,1]]) # False

(question seen as a Udacity programming course homework question)


highlight to see a solution:


def fn(x):
    b = [(j + 1) for j in range(0,len(x))]
    for i in x:
        if sorted(i) != b: return False
    return True

[More programming riddles]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s