check_sudoku
来源:互联网 发布:听歌识曲软件下载 编辑:程序博客网 时间:2024/05/22 04:39
# 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
0 0
- check_sudoku
- GitHub上最火的40个Android开源项目
- bind/function使用
- Centos 升级GLIBCXX
- EF二三事
- ClickableSpan造成Listview的OnItemClickListener失效的解决办法
- check_sudoku
- Android 自定义控件与属性
- 男子自制吸金球盗黄金数斤,狂赚200万
- Linux系统中 任务、进程和线程总结
- 《程序员的修炼——从优秀到卓越》
- wordpress建博客的步骤
- MySQL学习笔记之一 MySQL入门
- 【转Oracle补丁】老托的Oracle 数据库Patch概念性小常识
- css border 外边使用方法