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
8d6e62be
Commit
8d6e62be
authored
Jan 21, 2017
by
Vít Novotný
Browse files
added test outputs for examples 3.4_13--3.6_17
parent
6a8842fd
Changes
10
Show whitespace changes
Inline
Side-by-side
3.4_13-lifo.py
View file @
8d6e62be
...
...
@@ -17,10 +17,22 @@ def depth_first_search(start_node):
for
node1
in
move_anyY
(
node
):
paths
.
append
(
Cons
(
node1
,
path
))
def
is_goal
(
_
):
def
is_goal
(
x
):
# zavisi na resenem problemu
return
False
return
x
==
"E"
graph
=
dict
(
A
=
[
"B"
,
"E"
,
"F"
],
B
=
[
"C"
],
F
=
[
"C"
],
C
=
[
"D"
],
D
=
[
"E"
])
def
move_anyY
(
x
):
# zavisi na resenem problemu
yield
x
if
x
in
graph
:
for
y
in
graph
[
x
]:
yield
y
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
"Depth-First Search"
)
print
(
"Volani next(solution('A')) : %s"
%
next
(
solution
(
'A'
)))
3.4_13-lifo.py.out
View file @
8d6e62be
Depth-First Search
Volani next(solution('A')) : ['E', 'D', 'C', 'F', 'A']
3.4_13.py
View file @
8d6e62be
...
...
@@ -15,10 +15,22 @@ def depth_first_search(akumulator_path, node):
for
path
in
depth_first_search
(
akumulator_path1
,
node1
):
yield
path
def
is_goal
(
_
):
def
is_goal
(
x
):
# zavisi na resenem problemu
return
False
return
x
==
"E"
graph
=
dict
(
A
=
[
"B"
,
"E"
,
"F"
],
B
=
[
"C"
],
F
=
[
"C"
],
C
=
[
"D"
],
D
=
[
"E"
])
def
move_anyY
(
x
):
# zavisi na resenem problemu
yield
x
if
x
in
graph
:
for
y
in
graph
[
x
]:
yield
y
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
"Depth-First Search"
)
print
(
"Volani next(solution('A')) : %s"
%
next
(
solution
(
'A'
)))
3.4_13.py.out
View file @
8d6e62be
Depth-First Search
Volani next(solution('A')) : ['E', 'D', 'C', 'B', 'A']
3.5_15-lifo.py
View file @
8d6e62be
...
...
@@ -18,10 +18,26 @@ def depth_first_search(start_node, max_depth):
for
node1
in
move_anyY
(
node
):
paths
.
append
((
Cons
(
node1
,
path
),
remaining_depth
-
1
))
def
is_goal
(
_
):
def
is_goal
(
x
):
# zavisi na resenem problemu
return
False
return
x
==
"E"
graph
=
dict
(
A
=
[
"B"
,
"E"
,
"F"
],
B
=
[
"C"
],
F
=
[
"C"
],
C
=
[
"D"
],
D
=
[
"E"
])
def
move_anyY
(
x
):
# zavisi na resenem problemu
yield
x
if
x
in
graph
:
for
y
in
graph
[
x
]:
yield
y
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
"Depth-First Search"
)
print
(
"Volani next(solution('A')) : %s"
%
next
(
solution
(
'A'
)))
print
(
"Volani next(depth_first_search('A', 3)) : %s"
%
\
next
(
depth_first_search
(
'A'
,
3
)))
print
(
"Volani next(depth_first_search('A', 4)) : %s"
%
\
next
(
depth_first_search
(
'A'
,
4
)))
3.5_15-lifo.py.out
View file @
8d6e62be
Depth-First Search
Volani next(solution('A')) : ['E', 'D', 'C', 'F', 'A']
Volani next(depth_first_search('A', 3)) : ['E', 'A']
Volani next(depth_first_search('A', 4)) : ['E', 'D', 'C', 'F', 'A']
3.5_15.py
View file @
8d6e62be
...
...
@@ -17,10 +17,26 @@ def depth_first_search(akumulator_path, node, remaining_depth):
remaining_depth
-
1
):
yield
path
def
is_goal
(
_
):
def
is_goal
(
x
):
# zavisi na resenem problemu
return
False
return
x
==
"E"
graph
=
dict
(
A
=
[
"B"
,
"E"
,
"F"
],
B
=
[
"C"
],
F
=
[
"C"
],
C
=
[
"D"
],
D
=
[
"E"
])
def
move_anyY
(
x
):
# zavisi na resenem problemu
yield
x
if
x
in
graph
:
for
y
in
graph
[
x
]:
yield
y
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
"Depth-First Search"
)
print
(
"Volani next(solution('A')) : %s"
%
next
(
solution
(
'A'
)))
print
(
"Volani next(depth_first_search(Nil, 'A', 3)) : %s"
%
\
next
(
depth_first_search
(
Nil
,
'A'
,
3
)))
print
(
"Volani next(depth_first_search(Nil, 'A', 4)) : %s"
%
\
next
(
depth_first_search
(
Nil
,
'A'
,
4
)))
3.5_15.py.out
View file @
8d6e62be
Depth-First Search
Volani next(solution('A')) : ['E', 'D', 'C', 'B', 'A']
Volani next(depth_first_search(Nil, 'A', 3)) : ['E', 'A']
Volani next(depth_first_search(Nil, 'A', 4)) : ['E', 'D', 'C', 'B', 'A']
3.6_17.py
View file @
8d6e62be
...
...
@@ -4,7 +4,7 @@
from
linked_lists
import
LinkedList
,
Cons
,
Nil
def
solution
(
node
):
for
path
in
breadth_first_search
(
LinkedList
(
LinkedList
(
node
))):
for
path
in
breadth_first_search
(
LinkedList
(
[
LinkedList
(
node
)
]
)):
yield
path
def
breadth_first_search
(
paths
):
...
...
@@ -23,14 +23,6 @@ def breadth_first_search(paths):
for
path
in
breadth_first_search
(
paths1
):
yield
path
def
is_goal
(
_
):
# zavisi na resenem problemu
return
False
def
move_anyY
(
x
):
# zavisi na resenem problemu
yield
x
def
append
(
xs
,
ys
):
if
xs
==
Nil
:
return
ys
...
...
@@ -43,3 +35,23 @@ def member(x, xs):
if
x
==
xs
.
head
:
return
True
return
member
(
x
,
xs
.
tail
)
def
is_goal
(
x
):
# zavisi na resenem problemu
return
x
==
"E"
graph
=
dict
(
A
=
[
"B"
,
"E"
,
"F"
],
B
=
[
"C"
],
F
=
[
"C"
],
C
=
[
"D"
],
D
=
[
"E"
])
def
move_anyY
(
x
):
# zavisi na resenem problemu
if
x
in
graph
:
for
y
in
graph
[
x
]:
yield
y
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
"Breadth-First Search"
)
print
(
"Volani next(solution('A')) : %s"
%
next
(
solution
(
'A'
)))
3.6_17.py.out
View file @
8d6e62be
Breadth-First Search
Volani next(solution('A')) : ['E', 'A']
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