Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Vít Novotný
pb016-priklady
Commits
b1beb40c
Commit
b1beb40c
authored
Jan 19, 2017
by
Vít Novotný
Browse files
added example 3.2_4
parent
23adc4c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
3.2_4.pl
0 → 100644
View file @
b1beb40c
% nacteni:
/*
['3.2_4.pl'].
*/
:-
retractall
(
solution
/
1
).
:-
retractall
(
sol
/
1
).
:-
retractall
(
noattack
/
2
).
:-
retractall
(
template
/
1
).
:-
dynamic
solution
/
1
,
sol
/
1
,
noattack
/
2
,
template
/
1
.
solution
(
S
)
:-
template
(
S
),
sol
(
S
).
sol
([]).
sol
([
X
/
Y
|
Others
])
:-
sol
(
Others
),
% member(X, ...) zde nemusi byt, protoze X je jiz
% pevne nastavena v template. Ve slajdech take neni.
member
(
Y
,[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
]),
noattack
(
X
/
Y
,
Others
).
noattack
(
_
,[]).
noattack
(
X
/
Y
,[
X1
/
Y1
|
Others
])
:-
X
=
\
=
X1
,
Y
=
\
=
Y1
,
Y1
-
Y
=
\
=
X1
-
X
,
Y1
-
Y
=
\
=
X
-
X1
,
noattack
(
X
/
Y
,
Others
).
template
([
1
/
_Y1
,
2
/
_Y2
,
3
/
_Y3
,
4
/
_Y4
,
5
/
_Y5
,
6
/
_Y6
,
7
/
_Y7
,
8
/
_Y8
]).
% demonstracni vypis
% abychom se vyhli varovanim "Redefined static procedure ..."
:-
dynamic
start
/
0
.
start
:-
write
(
'PROBLEM OSMI DAM II - jeden sloupec pro kazdou damu'
),
nl
,
write
(
'Zadejte dotaz "solution(Solution)", po vypoctu prvniho reseni'
),
nl
,
write
(
'si dalsi vyzadate stisknutim ";" (vsimnete si zrychleni oproti'
),
nl
,
write
(
' verzi I).'
),
nl
.
?-
start
.
:-
retractall
(
start
/
0
).
3.2_4.py
0 → 100644
View file @
b1beb40c
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
from
linked_lists
import
Cons
,
Nil
def
solution
(
n
=
8
):
if
n
==
0
:
yield
Nil
else
:
for
others
in
solution
(
n
-
1
):
x
=
8
-
n
for
y
in
range
(
8
):
if
noattack
(
x
,
y
,
others
):
yield
Cons
((
x
,
y
),
others
)
def
noattack
(
x
,
y
,
others
):
if
others
==
Nil
:
return
True
else
:
x1
,
y1
=
others
.
head
return
x
!=
x1
and
y
!=
y1
and
y1
-
y
!=
x1
-
x
and
y1
-
y
!=
x
-
x1
and
\
noattack
(
x
,
y
,
others
.
tail
)
def
tisknireseni
(
reseni
):
return
[
"%d/%d"
%
(
x
+
1
,
y
+
1
)
for
(
x
,
y
)
in
reseni
]
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
"PROBLEM OSMI DAM I"
)
print
(
"Volani tisknireseni(next(solution())) : %s"
%
\
tisknireseni
(
next
(
solution
())))
3.2_4.py.out
0 → 100644
View file @
b1beb40c
PROBLEM OSMI DAM I
Volani tisknireseni(next(solution())) : ['1/4', '2/2', '3/7', '4/3', '5/6', '6/8', '7/5', '8/1']
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment