-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtranslation_solution.pro
64 lines (52 loc) · 1.55 KB
/
translation_solution.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
%!bp -g "['translation_solution.pro']"
%
% @author Manuel Ebert
% @system b-prolog
% Solution:
% Part 1:
fish --> ['the shark'].
fish --> ['the goldfish'].
bird --> ['the eagle'].
bird --> ['the finch'].
mammal --> ['the boy'].
carnivore --> ['the shark'].
carnivore --> ['the eagle'].
carnivore --> ['the boy'].
thing --> fish.
thing --> bird.
thing --> mammal.
drownable --> bird.
drownable --> mammal.
flying --> bird.
swimming --> fish.
swimming --> mammal.
s --> swimming, ['swims'].
s --> flying, ['flies'].
s --> carnivore, ['eats'], thing.
s --> thing, ['eats'].
s --> thing, ['drowns'], drownable.
s --> drownable, ['drowns'].
% Part 2:
english_words(['the shark', 'the goldfish', 'the eagle', 'the finch', 'the boy', 'eats', 'swims', 'flies', 'drowns']).
meaningful(L) :-
s(L, []).
translation(Nqrrroah, Nqblubh, Nqflua, Nqdwingi, Nqlhalha, Ukahama, Mhboa, Sharabrab, Falup) :-
english_words(E),
permutation([Nqrrroah, Nqblubh, Nqflua, Nqdwingi, Nqlhalha, Ukahama, Mhboa, Sharabrab, Falup], E),
meaningful([Nqblubh,Mhboa]),
meaningful([Nqrrroah,Ukahama,Nqblubh]),
meaningful([Nqlhalha,Falup]),
meaningful([Nqlhalha,Ukahama]),
meaningful([Nqlhalha,Ukahama,Nqflua]),
meaningful([Nqflua,Sharabrab]),
meaningful([Nqblubh,Falup,Nqdwingi]),
meaningful([Nqflua,Ukahama,Nqdwingi]),
meaningful([Nqdwingi,Falup,Nqflua]).
% permutation (if not built in)
permutation(List,[H|Perm]):-
delete(H,List,Rest),
permutation(Rest,Perm).
permutation([],[]).
delete(X,[X|T],T).
delete(X,[H|T],[H|NT]):-
delete(X,T,NT).