1. naloga ========= a) minBT(b(nil,E,nil), E). minBT(b(nil,E,R), Min) :- minBT(R, MR), min([E, MR], Min). minBT(b(L,E,nil), Min) :- minBT(L, ML), min([E, ML], Min). minBT(b(L,E,R), Min) :- minBT(L, ML), minBT(R, MR), min([ML, MR, E], Min). b) pathBT(E, b(_,E,_), []). pathBT(X, b(L,_,_), [left|PathL]) :- pathBT(X,L,PathL). pathBT(X, b(_,_,R), [right|PathR]) :- pathBT(X,R,PathR). 2. naloga ========= a) V jeziku sta besedi [a,b,c,d,e,f] in [a,b,b,a]. b) ?- s(M, [abcd], []). false. % pravzaprav se prolog zacikla (oba odgovora štejeta kot pravilna) ?- s(M, [a,b,c,d], []). M = [d,c,b,a]. c) Obrne dano besedo (če ima ta sodo število simbolov). 3. naloga ========= a) X = 1 ; X = 5. b) Lokacije, ki so več kot R oddaljene od točke XC/YC. c) ?- location(2.5/3, 2, X/Y). d) ?- findall(X/Y, location(2.5/3, 2, X/Y), L), length(L, NumberOfLocations). e) Žal nismo. Odgovori ostanejo enaki, delovanje tudi. Minimize namreč dela samo na *eni* možnosti, ne na vseh (ki bi jih z _vračanjem_ vrnil labeling) naenkrat. 4. naloga ========= a) A cat named Muri eats fish. exists(C, cat(C) and named(C, muri) and eats(C, fish)). b) Each turist from Osaka spoke to every guide who spoke Japanese. all(T, turist(T) and from(T, osaka) ==> all(G, guide(G) and spoke(G, japanese) ==> spoke_to(T, G))). c) A lucky student from Piran won two tickets for a trip to Hawaii. exists(S, student(S) and lucky(S) and from(S, piran) and exists(T, trip(T) and to(T, hawaii) and exists(T1, ticket(T1) and for(T1, T) and won(S, T1) and exists(T2, ticket(T2) and for(T2, T) and won(S, T2) and T1 \= T2)))). 5. naloga ========= Nekaj možnih rešitev: x := sqrt(2*x*x + 2*x*y) x := -sqrt(2*x*x + 2*x*y) y := x + y y := -(x + y) z := z - (x*x + 2*x*y)