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]

riddle 2 (python)


Count the number of days between two days.

same as last time, highlight to see answer(s), in python, below.

def fn(*args): 
      x = '/'.join(str(i) for i in args[:3])
      y = '/'.join(str(i) for i in args[3:])
      return abs((datetime.strptime(x,"%Y/%m/%d")-datetime.strptime(y,"%Y/%m/%d")).days)


#depending on input format, could do a one-liner:

def fn(x,y): abs((datetime.strptime(x,"%Y/%m/%d")-datetime.strptime(y,"%Y/%m/%d")).days)

#it's probably possible to replace "%Y/%m/%d" with "%c"

[More programming riddles]