2013-03-31 70 views
0

我經歷了一些Lewis Carrols logical quizzes 符號邏輯和我有一個頁面上有謎語數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究竟意味着什麼。二,如果我查詢序言:?- avoid(A)統一A = kangoroo 這是正確的答案,但我覺得很奇怪,take_to_mecan_kill_mice 謂詞不用於得到這個答案。 也許我沒有看到明顯的。

回答

1

要「接受」某件事就意味着要接受它。

避免(A)如果A是動物並且厭惡它,那麼它就會被滿足。你厭惡那些不適合你的東西。只有當它是一種家養動物時,你纔會接受某種東西。因此,袋鼠是正確的答案。