Advertisement
Guest User

Untitled

a guest
May 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. correct = [[1, 2, 3],
  2. [2, 3, 1],
  3. [3, 1, 2]]
  4.  
  5. incorrect = [[1, 2, 3, 4],
  6. [2, 3, 1, 3],
  7. [3, 1, 2, 3],
  8. [4, 4, 4, 4]]
  9.  
  10. incorrect2 = [[1, 2, 3, 4],
  11. [2, 3, 1, 4],
  12. [4, 1, 2, 3],
  13. [3, 4, 1, 2]]
  14.  
  15. incorrect3 = [[1, 2, 3, 4, 5],
  16. [2, 3, 1, 5, 6],
  17. [4, 5, 2, 1, 3],
  18. [3, 4, 5, 2, 1],
  19. [5, 6, 4, 3, 2]]
  20.  
  21. incorrect4 = [['a', 'b', 'c'],
  22. ['b', 'c', 'a'],
  23. ['c', 'a', 'b']]
  24.  
  25. incorrect5 = [[1, 1.5],
  26. [1.5, 1]]
  27.  
  28.  
  29. def check_sudoku(p):
  30. n = len(p)
  31. digit = 1
  32. while digit <= n:
  33. i = 0
  34. while i < n:
  35. row_count = 0
  36. col_count = 0
  37. j = 0
  38. while j < n:
  39. if p[i][j] == digit:
  40. row_count = row_count + 1
  41. if p[j][i] == digit:
  42. col_count = col_count + 1
  43. j = j + 1
  44. if row_count != 1 or col_count != 1:
  45. return False
  46. i = i + 1
  47. digit = digit + 1
  48. return True
  49.  
  50. print(check_sudoku(incorrect))
  51. print(check_sudoku(correct))
  52. print(check_sudoku(incorrect2))
  53. print(check_sudoku(incorrect3))
  54. print(check_sudoku(incorrect4))
  55. print(check_sudoku(incorrect5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement