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

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 17:10
点赞 评论 收藏
分享
小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
07-09 19:25
门头沟学院 Java
这是要把每一个投校招的都开盒吗?
26届之耻将大局逆转:裁人的时候一次性追回餐费
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务