Advertisement
Guest User

Untitled

a guest
Aug 12th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. def goriz(board):
  2. for i in range(9):
  3. sum = 0
  4. for j in range(9):
  5. sum += board[i][j]
  6. if sum != 45:
  7. return 0
  8. return 1
  9.  
  10. def vert(board):
  11. for i in range(9):
  12. sum = 0
  13. for j in range(9):
  14. sum += board[j][i]
  15. if sum != 45:
  16. return 0
  17. return 1
  18.  
  19. def kvadr(board, i, j):
  20. sum = 0
  21. for a in range(3):
  22. for b in range(3):
  23. sum += board[i + a][j + b]
  24. if sum != 45:
  25. return 0
  26. else:
  27. return 1
  28.  
  29. def skv(board):
  30. res = 1
  31. for i in range(3):
  32. for j in range(3):
  33. res = res & kvadr(board, i * 3, j * 3)
  34. return res
  35.  
  36. def solution(board):
  37. res = 1
  38. sum = 0
  39. for i in range(9):
  40. for j in range(9):
  41. sum += board[i][j]
  42. if sum != 405:
  43. res = 0
  44. return res & skv(board) & goriz(board) & vert(board)
  45.  
  46.  
  47.  
  48. s = [
  49. [4, 3, 4, 6, 7, 8, 9, 1, 3],
  50. [6, 7, 2, 1, 9, 5, 3, 4, 8],
  51. [2, 9, 8, 3, 4, 2, 5, 6, 6],
  52. [8, 5, 9, 7, 6, 1, 4, 2, 3],
  53. [4, 2, 6, 8, 5, 3, 7, 9, 1],
  54. [7, 1, 3, 9, 2, 4, 8, 5, 6],
  55. [9, 6, 1, 5, 3, 7, 2, 8, 4],
  56. [2, 8, 7, 4, 1, 9, 6, 3, 5],
  57. [3, 4, 5, 2, 8, 6, 1, 7, 9]
  58. ]
  59. res = solution(s)
  60. print(res)
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement