Part A
In a simplified game of Scrabble, the score for a particular word is always calculated by simply adding up the points for each letter in the word. The points for each letter in the alphabet are represented in the following Prolog program as 26 facts:
scrabble_points(a, 1).
scrabble_points(b, 3).
scrabble_points(c, 3).
scrabble_points(d, 2).
scrabble_points(e, 1).
scrabble_points(f, 4).
scrabble_points(g, 2).
scrabble_points(h, 4).
scrabble_points(i, 1).
scrabble_points(j, 8).
scrabble_points(k, 5).
scrabble_points(l, 1).
scrabble_points(m, 3).
scrabble_points(n, 1).
scrabble_points(o, 1).
scrabble_points(p, 3).
scrabble_points(q, 10).
scrabble_points(r, 1).
scrabble_points(s, 1).
scrabble_points(t, 1).
scrabble_points(u, 1).
scrabble_points(v, 4).
scrabble_points(w, 4).
scrabble_points(x, 8).
scrabble_points(y, 4).
scrabble_points(z, 10).
Add a definition for the predicate ‘scrabble_score/2’ to this program, that has a list of lowercase letters (representing a word) as the first argument and a number as the second argument. The query ‘?- scrabble_score(Word, Score)’ should succeed if and only if Score is the Scrabble score for the word represented in the list Word. Your answer should reproduce the following example input/output:
?- scrabble_score([s, c, r, a, b, b, l, e], Scrabble_score).
Scrabble_score = 14.
Part B
Write a program that includes a definition for the predicate ‘word_with_replacements/2’. This predicate should be true if the two arguments are lists, and the second list is the same as the first but with all elements that are the single letter ‘a’ replaced by the letter ‘e’, and with all elements that are the single letter ‘e’ replaced by the letter ‘a’. Your answer should reproduce the following example input/output:
?- word_with_replacements([s, c, r, a, b, b, l, e], Word_with_replacements).
Word_with_replacements = [s, c, r, e, b, b, l, a] ;
false.
?- word_with_replacements(Word, [s, c, r, e, b, b, l, a]).
Word = [s, c, r, a, b, b, l, e] ;
false.
(Ideally, the program should be written so that it would be very easy at a later date to specify that more letters should be replaced with others, simply by adding facts to the program.)