@PeterUdacity or @fnenu I'd appreciate it if you would respond. When I hit submit now it says this solution is correct. I have also run it against the test cases posted on this forum and it passes all except for one that inputs an invalid Sudoku square ([1,2,3],[2,3,1],[3,1,2,1]). If there is a valid test case that my code does not pass or you haven't gotten around to doing all of the re-grading please let me know. Otherwise, I think my progress for this homework problem should be updated to 'Correct'. Thanks. Here is my code:
def check_sudoku(p):
if p == None: # invalid array check
return False
largest = len(p)
columns = []
rownum = 0
if largest == 0 or len(p[0]) != largest: # invalid array checks
return False
while rownum < largest:
testrow = []
colnum = 0
while colnum < largest:
val = p[rownum][colnum]
if val < 1 or val > largest:
return False
if val in testrow:
return False
testrow.append(val)
if rownum == 0:
testcol = []
columns.append(testcol)
if val in columns[colnum]:
return False
columns[colnum].append(val)
colnum += 1
rownum += 1
return True
asked
07 Apr '12, 17:34
Van Dillon
1.9k●1●4●25
accept rate:
25%