### Thread: Help with a problem?

1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Posts
100
Rep Power
2

#### Help with a problem?

Here's the problem:
Code:
```# 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
# otherwise.

# 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],
#            [2,3,1,3],
#           [3,1,2,3],
#           [4,4,4,4]]"```
Now, I've thought about breaking this problem down to two parts -- 1st will check for rows, the 2nd will check for columns.
EDIT: The first one is done, I need a solution for the second one(columns).
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.
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Posts
100
Rep Power
2
Also, the code I used for rows is this:
Code:
```def row_check(x):
for ealst in x:
first = [ealst[0]]
for each in ealst[1:]:
if each not in first:
first.append(each)
else:
return False
return True```
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?
Last edited by Akshat1; June 16th, 2013 at 10:31 AM.
3. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
May 2009
Posts
530
Rep Power
34
The "return "False" is executed first.
Code:
```def testit(value_in):
if 0 == value_in:
return False
return True

for val in [0, 1, 0, 2, 3]:
print val, testit(val)```