Commit b5e683ce authored by Vít Novotný's avatar Vít Novotný
Browse files

added example 3.4_13

parent c6fd009f
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
from linked_lists import Cons, Nil
def solution(node):
for path in depth_first_search(node):
yield path
def depth_first_search(start_node):
paths = [Cons(start_node, Nil)] # pouzijeme pythonovsky seznam jako LIFO
while len(paths) > 0:
path = paths.pop()
node = path.head
if is_goal(node):
yield path
for node1 in move_anyY(node):
paths.append(Cons(node1, path))
def is_goal(_):
# zavisi na resenem problemu
return False
def move_anyY(x):
# zavisi na resenem problemu
yield x
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
from linked_lists import Cons, Nil
def solution(node):
for path in depth_first_search(Nil, node):
yield path
def depth_first_search(akumulator_path, node):
akumulator_path1 = Cons(node, akumulator_path)
if is_goal(node):
yield akumulator_path1
for node1 in move_anyY(node):
for path in depth_first_search(akumulator_path1, node1):
yield path
def is_goal(_):
# zavisi na resenem problemu
return False
def move_anyY(x):
# zavisi na resenem problemu
yield x
% nacteni:
/* ['3.4_13.pl']. */
solution(Node,Solution) :- depth_first_search([], Node,Solution).
depth_first_search(Path,Node,[Node|Path]) :- goal(Node).
depth_first_search(Path,Node,Sol) :- move(Node,Node1),
\+ member(Node1,Path),depth_first_search([Node|Path],Node1,Sol).
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment