Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def goriz(board):
- for i in range(9):
- sum = 0
- for j in range(9):
- sum += board[i][j]
- if sum != 45:
- return 0
- return 1
- def vert(board):
- for i in range(9):
- sum = 0
- for j in range(9):
- sum += board[j][i]
- if sum != 45:
- return 0
- return 1
- def kvadr(board, i, j):
- sum = 0
- for a in range(3):
- for b in range(3):
- sum += board[i + a][j + b]
- if sum != 45:
- return 0
- else:
- return 1
- def skv(board):
- res = 1
- for i in range(3):
- for j in range(3):
- res = res & kvadr(board, i * 3, j * 3)
- return res
- def solution(board):
- res = 1
- sum = 0
- for i in range(9):
- for j in range(9):
- sum += board[i][j]
- if sum != 405:
- res = 0
- return res & skv(board) & goriz(board) & vert(board)
- s = [
- [4, 3, 4, 6, 7, 8, 9, 1, 3],
- [6, 7, 2, 1, 9, 5, 3, 4, 8],
- [2, 9, 8, 3, 4, 2, 5, 6, 6],
- [8, 5, 9, 7, 6, 1, 4, 2, 3],
- [4, 2, 6, 8, 5, 3, 7, 9, 1],
- [7, 1, 3, 9, 2, 4, 8, 5, 6],
- [9, 6, 1, 5, 3, 7, 2, 8, 4],
- [2, 8, 7, 4, 1, 9, 6, 3, 5],
- [3, 4, 5, 2, 8, 6, 1, 7, 9]
- ]
- res = solution(s)
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement