# HW 3 Sudoku

 0 This has been graded as incorrect. Could anyone tell me what is wrong with this answer? (If posting this code is not appropriate I will delete it). Thank you! #THREE GOLD STARS #Sudoku [http://en.wikipedia.org/wiki/Sudoku] #is a logic puzzle where a game #is defined by a partially filled #9 x 9 square of digits where each square #contains one of the digits 1,2,3,4,5,6,7,8,9. #For this question we will generalize #and simplify the game. #Define a procedure, check_sudoku, #that takes as input a square list #of lists representing an n x n #sudoku puzzle solution and returns #True if the input is a valid #sudoku square and returns False #otherwise. #A valid sudoku square satisfies these #two properties: # 1. Each column of the square contains # each of the numbers from 1 to n exactly once. # 2. Each row of the square contains each # of the numbers from 1 to n exactly once. correct = [[1,2,3], [2,3,1], [3,1,2]] incorrect = [[1,2,3,4], [2,4,1,3], [4,1,2,3], [1,2,3,4]] def check_sudoku(list): row = [] column = [] counter = 0 while counter < len(list): for x in list: if x[counter] in column: return False else: column.append(x[counter]) column = [] counter = counter + 1 for x in list: for y in x: if y in row: return False else: row.append(y) row = [] return True print check_sudoku(correct) print check_sudoku(incorrect)  asked 14 Mar '12, 19:27 Tadeusz Jordan 148●1●1●18 accept rate: 85%

 0 No, it was correctly graded as wrong! It fails those tests: incorrect3 = [[1,2,3],[4,5,6],[7,8,9]] incorrect35 = [[0,2,3],[2,3,1],[3,1,2]] You did not validate the minimum/maximum value. And it is not an invalid post! :) answered 14 Mar '12, 20:09 Angel 7.0k●6●32●112
 1 I did the same thing :/ Thanks to angel for pointing it out. answered 14 Mar '12, 23:05 Douglas Finn... 146●1●3●9
 0 ahh I forgot to check if the numbers are out of range :) Thanks! answered 14 Mar '12, 20:11 Tadeusz Jordan 148●1●1●18
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

×15,330
×195
×13