1

我正在做一些刘易斯卡罗尔逻辑测验 ,我在那个页面上有一个谜语号 60 的问题:

(1) The only animals in this house are cats; 
(2) Every animal is suitable for a pet, that loves to gaze at the moon; 
(3) When I detest an animal, I avoid it; 
(4) No animals are carnivorous, unless they prowl at night; 
(5) No cat fails to kill mice; 
(6) No animals ever take to me, except what are in this house; 
(7) Kangaroos are not suitable for pets; 
(8) None but carnivora kill mice; 
(9) I detest animals that do not take to me; 
(10) Animals, that prowl at night, always love to gaze at the moon. 
Univ. "animals"; a = avoided by me; b = carnivora; c = cats; d = detested by me;
e = in this house; h = kangaroos; k = killing mice; l = loving to gaze at the moon;
m = prowling at night; n = suitable for pets, r = taking to me.

现在我想出了以下 Prolog 程序:

animal(cat).
animal(kangaroo).

prowl_at_night(cat).

carnivore(A) :- prowl_at_night(A).

loves_moongazing(A) :- prowl_at_night(A).

animals_in_house(cat).

suitable_pet(A) :-
    animal(A),
    A \= kangaroo,
    loves_moongazing(A).

can_kill_mice(cat).
can_kill_mice(A) :- carnivore(A).

take_to_me(A) :- animals_in_house(A).

detest(A) :- \+ take_to_me(A).

avoid(A) :- animal(A), detest(A).

现在首先我不确定taking to me实际上是什么意思。其次,如果我查询 Prolog: ?- avoid(A)unifies with A = kangoroo which 是正确的答案,但我觉得奇怪的是,take_to_meandcan_kill_mice 谓词不用于得到这个答案。也许我没有看到明显的东西。

4

1 回答 1

2

“接受”某事意味着依附于它。

如果 A 是动物并且您讨厌它,则避免(A)满足。你讨厌不喜欢你的东西。只有当它是家畜时,你才会接受它。因此,袋鼠是正确的答案。

于 2013-03-31T20:39:46.267 回答