Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
blastLittleTiger
algorithm-by-python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
algorithm-by-python
/
sudoku.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
62 lines (51 loc) · 1.46 KB
master
Breadcrumbs
algorithm-by-python
/
sudoku.py
Copy path
Top
File metadata and controls
Code
Blame
62 lines (51 loc) · 1.46 KB
Raw
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
You can’t perform that action at this time.