Rešitve izpita PPJ 26. 6. 2014 1. naloga ========= maxPath(nil, 0). maxPath(b(L, E, R), Max) :- maxPath(L, MaxL), maxPath(R, MaxR), (MaxL > MaxR, Max is MaxL + E ; MaxL =< MaxR, Max is MaxR + E). 2. naloga ========= a) compound --> []. compound --> element, compound. b) compound / \ / \ element compound | / \ 'Ca' / \ element compound | / \ 'C' / \ element compound / \ | 'O' \ [] number | 3 c) number(N) --> [N], { integer(N) }. element(W) --> [X], { atom(X, W) }. element(W) --> [X], number(N), { atom(X, WA), W is WA * N }. compound(0) --> []. compound(W) --> element(WE), compound(WC), { W is WE + WC }. 3. naloga ========= a) f(1, Y) Y = 1 f(-2, Y) Y = 2 f(X, 3) X = 3 ; X = -3 f(X, -4) no f(5, 5) yes f(-6, 6) yes b) Absolutna vrednost. c) Deluje v vse smeri (s poljubnimi argumenti). 4. naloga ========= (manjka) 5. naloga ========= a) all(C, cat(C) => all(D, dog(D) and drinks(D, milk) => likes(C, D))). b) exists(T, trip(T) and to(T, istanbul) and all(P, tourist(P) and from(P, london) and P \= mary => liked(P, T))). c) all(S, student(S) and exists(P, school_project(P) and finished(S, P)) => exists(M, mark(M) and received(P, M) and M > 7)).