check_sudoku

# Define a procedure, check_sudoku,
# that takes as input a square list
# of lists representing an n x n
# sudoku puzzle solution and returns the boolean
# True if the input is a valid
# sudoku square and returns the boolean False
# otherwise.

# A valid sudoku square satisfies these
# two properties:

#   1. Each column of the square contains
#       each of the whole numbers from 1 to n exactly once.

#   2. Each row of the square contains each
#       of the whole numbers from 1 to n exactly once.

# You may assume the the input is square and contains at
# least one row and column.



def rowcheck(l):
    sign=1
    for i in l:
        original=[1,2,3,4,5,6,7,8,9]
        p=original[:len(l)]
        for j in p:
            if j not in i:
                sign=-1
                break
            else:
                pos = i.index(j)
                k=i[pos+1:]
                if j in k:
                    sign=-1
                    break      
    if sign==1:
        return True
    else:
        return False
    
   
def colcheck(l):
    i=0
    p=l+[1,3,3]
    while i<len(l):
        j=0
        while j<len(l):
            l[i][j]=p[j][i]
            j=j+1
        i=i+1
    return rowcheck(l)
def check_sudoku(a):
    if rowcheck(a)==True and colcheck(a)==True:
        return True
    else:
        return False

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值