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
6d4c7dae
Commit
6d4c7dae
authored
Jan 18, 2017
by
Vít Novotný
Browse files
added example 2.9.1_21
parent
c9b33f46
Changes
4
Hide whitespace changes
Inline
Side-by-side
2.9.1_21.pl
0 → 100644
View file @
6d4c7dae
% nacteni:
/*
['2.9.1_21.pl'].
*/
path
(
A
,
Z
,
Graph
,
Cesta
)
:-
path1
(
A
,[
Z
],
Graph
,
Cesta
).
path1
(
A
,[
A
|
Cesta1
],
_
,[
A
|
Cesta1
]).
path1
(
A
,[
Y
|
Cesta1
],
Graph
,
Cesta
)
:-
adjacent
(
X
,
Y
,
Graph
),
\
+
member
(
X
,
Cesta1
),
path1
(
A
,[
X
,
Y
|
Cesta1
],
Graph
,
Cesta
).
adjacent
(
X
,
Y
,
graph
(
_
,
Edges
))
:-
member
(
e
(
X
,
Y
),
Edges
)
;
member
(
e
(
Y
,
X
),
Edges
).
graph
([
a
,
b
,
c
,
d
],[
e
(
a
,
b
),
e
(
b
,
d
),
e
(
b
,
c
),
e
(
c
,
d
)]).
% demonstracni vypis
start
:-
write
(
'Cesta v grafu'
),
nl
,
nl
,
write
(
'path(a, c, graph, Cesta) : '
),
graph
(
Nodes
,
Edges
),
path
(
a
,
c
,
graph
(
Nodes
,
Edges
),
Cesta
),
write
(
Cesta
),
nl
,
nl
.
?-
start
.
2.9.1_21.py
0 → 100644
View file @
6d4c7dae
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
from
linked_lists
import
LinkedList
,
Cons
,
Nil
def
path
(
a
,
z
,
graph
):
for
cesta
in
path1
(
a
,
LinkedList
(
z
),
graph
,
1
):
yield
cesta
def
path1
(
a
,
akumulator_cesty
,
graph
,
depth
):
if
akumulator_cesty
.
head
==
a
:
yield
akumulator_cesty
else
:
y
=
akumulator_cesty
.
head
for
x
in
adjacent_anyX
(
y
,
graph
):
if
not
member
(
x
,
akumulator_cesty
):
for
cesta
in
path1
(
a
,
Cons
(
x
,
akumulator_cesty
),
graph
,
depth
+
1
):
yield
cesta
def
adjacent_anyX
(
y
,
graph
):
_
,
edges
=
graph
for
a
,
b
in
member_anyX
(
edges
):
if
y
==
a
:
yield
b
if
y
==
b
:
yield
a
def
member
(
x
,
xs
):
if
xs
==
Nil
:
return
False
if
x
==
xs
.
head
:
return
True
return
member
(
x
,
xs
.
tail
)
def
member_anyX
(
xs
):
if
xs
==
Nil
:
return
yield
xs
.
head
for
x
in
member_anyX
(
xs
.
tail
):
yield
x
_graph
=
(
LinkedList
(
"a"
,
"b"
,
"c"
,
"d"
),
LinkedList
((
"a"
,
"b"
),
(
"b"
,
"d"
),
(
"b"
,
"c"
),
(
"c"
,
"d"
)))
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
'Cesta v grafu
\n
'
)
print
(
'next(path("a", "c", _graph)) : %s'
%
next
(
path
(
"a"
,
"c"
,
_graph
)))
2.9.1_21.py.out
0 → 100644
View file @
6d4c7dae
Cesta v grafu
next(path("a", "c", _graph)) : [a, b, c]
Makefile
View file @
6d4c7dae
.PHONY
:
tests output pylint2 pylint3
IGNORED_PYLINT_TESTS
=
invalid-name missing-docstring
\
redefined-variable-type too-few-public-methods
IGNORED_PYLINT2_TESTS
=
superfluous-parens
duplicate-code
IGNORED_PYLINT3_TESTS
=
duplicate-code
redefined-variable-type too-few-public-methods
duplicate-code
IGNORED_PYLINT2_TESTS
=
superfluous-parens
IGNORED_PYLINT3_TESTS
=
tests
:
# all tests
...
...
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