June 16th, 2013, 10:19 AM
Help with a problem?
Here's the problem:
Now, I've thought about breaking this problem down to two parts -- 1st will check for rows, the 2nd will check for columns.
# Define a procedure, check_sudoku,
# that takes as input a square list
# of lists representing an n x n
# sudoku puzzle solution and returns the boolean
# True if the input is a valid
# sudoku square and returns the boolean False
# A valid sudoku square satisfies these
# two properties:
# 1. Each column of the square contains
# each of the whole numbers from 1 to n exactly once.
# 2. Each row of the square contains each
# of the whole numbers from 1 to n exactly once.
# example of an input -
#"incorrect = [[1,2,3,4],
EDIT: The first one is done, I need a solution for the second one(columns).
Thanks, in advance.
Also, if you have a better approach to solve the problem, then you are most welcome.
Last edited by Akshat1; June 16th, 2013 at 10:21 AM.
June 16th, 2013, 10:29 AM
Also, the code I used for rows is this:
The whole code is written by me, except the last return statement. The only thing I am not understanding is that when the last return statement returns true and is independent of any condition(s), why doesn't the code always return True regardless of whether the input is correct or not?
for ealst in x:
first = [ealst]
for each in ealst[1:]:
if each not in first:
Last edited by Akshat1; June 16th, 2013 at 10:31 AM.
June 16th, 2013, 01:28 PM
The "return "False" is executed first.
if 0 == value_in:
for val in [0, 1, 0, 2, 3]:
print val, testit(val)