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

added example 3.6_17

parent aaca4d6d
% nacteni:
/* ['3.6_17.pl']. */
solution(Start ,Solution) :- breadth_first_search([[ Start ]], Solution).
breadth_first_search([[ Node|Path]|_],[Node|Path]) :- goal(Node).
breadth_first_search([[ N|Path]|Paths],Solution) :-
bagof([M,N|Path],(move(N,M),\+ member(M,[N|Path])), NewPaths),
NewPaths\=[], append(Paths,NewPaths,Path1), !,
breadth_first_search(Path1,Solution); breadth_first_search(Paths,Solution).
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
from linked_lists import LinkedList, Cons, Nil
def solution(node):
for path in breadth_first_search(LinkedList(LinkedList(node))):
yield path
def breadth_first_search(paths):
path = paths.head
node = path.head
if is_goal(node):
yield path
new_paths = Nil
for node1 in move_anyY(node):
if not member(node1, path):
new_paths = Cons(Cons(node1, path), new_paths)
if new_paths != Nil:
paths1 = append(paths.tail, new_paths)
else:
paths1 = paths.tail
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
else:
return Cons(xs.head, append(xs.tail, ys))
def member(x, xs):
if xs == Nil:
return False
if x == xs.head:
return True
return member(x, xs.tail)
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