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

added example 3.5_15

parent b5e683ce
#!/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, 999):
yield path
def depth_first_search(start_node, max_depth):
paths = [(Cons(start_node, Nil), max_depth)] # pouzijeme pythonovsky seznam jako LIFO
while len(paths) > 0:
path, remaining_depth = paths.pop()
node = path.head
if is_goal(node):
yield path
if remaining_depth > 0:
for node1 in move_anyY(node):
paths.append((Cons(node1, path), remaining_depth-1))
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, 999):
yield path
def depth_first_search(akumulator_path, node, remaining_depth):
akumulator_path1 = Cons(node, akumulator_path)
if is_goal(node):
yield akumulator_path1
if remaining_depth > 0:
for node1 in move_anyY(node):
for path in depth_first_search(akumulator_path1, node1,
remaining_depth-1):
yield path
def is_goal(_):
# zavisi na resenem problemu
return False
def move_anyY(x):
# zavisi na resenem problemu
yield x
% nacteni:
/* ['3.5_15.pl']. */
solution(Node,Solution) :- depth_first_search_limit(Node,Solution,999).
depth_first_search_limit(Node,[Node], _) :- goal(Node).
depth_first_search_limit(Node,[Node|Sol],MaxDepth) :- MaxDepth>0, move(Node,Node1),
Max1 is MaxDepth-1,depth_first_search_limit(Node1,Sol,Max1).
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