Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
62 lines (51 loc) · 1.46 KB

File metadata and controls

62 lines (51 loc) · 1.46 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env python
#coding:utf-8
#判断输入的九宫格的格数是否为奇数
def if_odd(n):
if n%2==1:
return True
else:
return False
#九宫格填写数的法则
"""
按照下面的方式排列
-------------->x(从1到n)
|
|
|y方向(从1到n)
1、第一个数放在X方向的中间位置
2、其它数顺次放置各个位置,并依据如下原则:(假设第一个数是a,第二个数是b)
以a为中心的位置关系分别为:
左上|上|右上
左 |a |右
左下|下|右下
(1)b放在a的右上位置。a(x,y)-->b(x+1,y-1)
(2)如果仅有“右”位置超过边界,即x+1>n,则b(1,y-1)
(3)如果仅有“上”位置超过边界,即y-1<0,则b(x+1,n)
(4)如果“右”“上”位置都超过边界,即x+1>n,y-1<o,则b(x,y+1)
(5)如果“右上”已经有值,则b(x,y+1)
"""
def sudoku_rule(n,sudoku):
tx = n/2
ty = 0
for i in range(n*n):
sudoku[ty][tx] = i+1
tx = tx+1
ty = ty-1
if ty<0 and tx>=n: #条件(4)
tx = tx-1
ty = ty+2
elif ty<0: #(3)
ty = n-1
elif tx>=n: #(2)
tx = 0
elif sudoku[ty][tx]!=0: #(5)
tx = tx-1
ty = ty+2
return sudoku
if __name__=="__main__":
n = 5
sudoku = [[0 for i in range(n)] for i in range(n)]
s = sudoku_rule(n,sudoku)
for line in s:
print line
Morty Proxy This is a proxified and sanitized view of the page, visit original site.