Rešitve izpita PPJ 19. 6. 2015 1. naloga ========= a) ?- smoothie(tropical, L, _). b) L = [berries,tropical,pinacolada,kiwi] c) which_smoothie(L, S) :- smoothie(S, Ingr, _), is_subset(Ingr, L). d) cheapest_smoothie(S) :- smoothie(S, _, Cost), \+ (smoothie(S1, _, Cost1), Cost1 < Cost). -ali- cheapest_smoothie(S) :- findall(Cost, smoothie(S, _, Cost), Costs), min(Costs, Min), smoothie(S, _, Min). 2. naloga ========= a) prva_crka(Word, Char) :- atom_chars(Word, [Char|_]). b) beseda([Char]) --> [X], { prva_crka(X, Char) }. kratica([]) --> []. kratica(Chars) --> beseda(Chars1), kratica(Chars2), { conc(Chars1, Chars2, Chars) }. c) beseda(L) --> [X], { atom_length(X, Len), ( Len > 2, !, prva_crka(X, Char), L = [Char] ; L = [] ) }. 3. naloga ========= a) B = [1,2,3] ; B = [1,3,2] ; B = [2,1,3] ; B = [2,3,1] ; B = [3,1,2] ; B = [3,2,1]. b) Program vrne vse permutacije števil od 1 do A. c) Če rez postavimo za ciljem labeling, program vrne samo prvi odgovor. Če rez postavimo za ciljem all_different, program vrne enako kot brez reza. 4. naloga ========= a) Tanya fears all her neighbours. all(N, neighbour(N, tanya) ==> fears(tanya, N)). b) Mary forgot a present that she received from a friend. exists(P, present(P) and exists(F, friend(F, mary) and from(P, F)) and received(mary, P) and forgot(mary, P)). c) John received a warning from a lady that monitors all prisoners. exists(L, lady(L) and all(P, prisoner(P) ==> monitors(L, P)) and exists(W, warning(W) and from(W, L) and received(john, W))). 5. naloga ========= a) p(x,y) = (x > y => 1 ≤ x^2-y^2) and (x ≤ y => 1 ≤ y^2-x^2) b) Φ(x) => (x > x+1 => 1 ≤ x^2-(x+1)^2) and (x ≤ x+1 => 1 ≤ (x+1)^2-x^2) -ali- Φ(x) => (x > x+1 and 1 ≤ x^2-(x+1)^2) or (x ≤ x+1 and 1 ≤ (x+1)^2-x^2) (poenostavljeno: x > 2 ⇒ x ≥ 0)