Task 10.1
Define a predicate bizarreTranslator/2 such that bizarreTranslator(L1, L2) takes an
input list L1 and generates an output list L2. L1 contains letters a-z; L2 is L1 with all
‘a’, ‘e’, ‘i,’, ‘o’ and ‘u’ replaced by ‘1’, ‘2’, ‘3’, ‘4’ and ‘5’, respectively. For instance:
?- bizarreTranslator([‘a’, ‘p’, ‘p’, ‘l’, ‘e’], X).
X = [1, p, p, l, 2] ;
false.
Task:10.2:
Let Board positions B be represented by a list of lists:
E.g., [[1,1],[2,3],[3,2]] denotes the board position where three queens are placed as
follows:
Q – –
– – Q
– Q –
Write a predicate straight(B) that checks whether in board position B there are two
queens in the same row (or column). Hint: use the member predicate.
Task 10.3
Consider the following knowledge base:
sumsqrs([],0).
sumsqrs([X|Xs],S) :-
sumsqrs(Xs,Ss),
S is X*X + Ss.
Call the knowledge base with a suitable query that explains what it computes.
Write second predicate computing the same with an accumulating argument.
Task 10. 4
Given the output
Prolog and Java
Which of the following produces it and why?
X=3,write(‘Prolog ‘),X==3,write(‘and ‘),1+2 is X,write(‘Java ‘).
X is 3,write(‘Prolog ‘),X=3,write(‘and ‘),X==3,write(‘Java ‘).
X==3,write(‘Prolog ‘),3 is X,write(‘and ‘),X=3,write(‘Java ‘).