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

全部评论

相关推荐

这算盘打的
程序员小白条:都这样的,都是潜规则,你自己说可以实习一年就行了,实习可以随便跑路的
点赞 评论 收藏
分享
05-26 10:24
门头沟学院 Java
qq乃乃好喝到咩噗茶:其实是对的,线上面试容易被人当野怪刷了
找工作时遇到的神仙HR
点赞 评论 收藏
分享
Rena1ssanc...:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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