Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AI Progamming Exercises
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Mutote
AI Progamming Exercises
Commits
0d4af7c7
Commit
0d4af7c7
authored
1 year ago
by
tnbeats
Browse files
Options
Downloads
Patches
Plain Diff
22211572
parent
6a947602
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
4_9_Exercises/Question 5.py
+35
-0
35 additions, 0 deletions
4_9_Exercises/Question 5.py
with
35 additions
and
0 deletions
4_9_Exercises/Question 5.py
0 → 100644
+
35
−
0
View file @
0d4af7c7
import
random
def
is_valid
(
board
,
row
,
col
):
for
i
in
range
(
8
):
if
board
[
i
][
col
]
or
board
[
row
][
i
]:
return
False
if
(
row
+
i
<
8
and
col
+
i
<
8
and
board
[
row
+
i
][
col
+
i
])
or
\
(
row
-
i
>=
0
and
col
-
i
>=
0
and
board
[
row
-
i
][
col
-
i
])
or
\
(
row
+
i
<
8
and
col
-
i
>=
0
and
board
[
row
+
i
][
col
-
i
])
or
\
(
row
-
i
>=
0
and
col
+
i
<
8
and
board
[
row
-
i
][
col
+
i
]):
return
False
return
True
def
solutions_generator
(
board
,
row
):
if
row
==
8
:
yield
[
row
.
copy
()
for
row
in
board
]
return
for
col
in
range
(
8
):
if
is_valid
(
board
,
row
,
col
):
board
[
row
][
col
]
=
1
yield
from
solutions_generator
(
board
,
row
+
1
)
board
[
row
][
col
]
=
0
def
solve
():
board
=
[[
0
]
*
8
for
_
in
range
(
8
)]
yield
from
solutions_generator
(
board
,
0
)
for
solution
in
solve
():
for
row
in
solution
:
print
(
row
)
print
(
"
--------
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment