-1

Unfortunately, I cannot give the full text of the problem for some reason. Therefore, I will try to describe the main point.

There was a murder at the hotel in room 4. 6 visitors are suspected who came to visit someone in one of the 6 hotel rooms at different intervals (These are all facts). Then all the suspects were interviewed, some evidence was considered and information was received from the receptionist (These are the rules). You need to find out who was where at what time. Well, and therefore who is the killer.

my problem I am not getting the correct result. When calling

guest(brown, R, T).

i get false (brawn must be a killer)

and basically when i call the function

solution(Guests).

then I get a very large number of lists. And the rules are not followed in them. Why is that? result lists screenshoot

In short, I have a suspicion that these rules work somehow separately. But I could be wrong, because in the prologue I am a complete zero. What's my mistake?

P.S. If necessary, I can try to write the full text of the assignment. The only problem is that the text is in a different language from an old book that was scanned..

1i10
  • 5
  • 4
  • Doing `name(N1), name(N2), name(N3), name(N4), name(N5), name(N6), unique(N1,N2,N3,N4,N5,N6)` is incredibly inefficient. It's `O(n^2)`. You should try to test before generating. – Enigmativity Nov 27 '21 at 10:02
  • It would be awesome to get the text (in English) of the original problem. I feel like you're making it much harder with all of the `not` predicates. – Enigmativity Nov 27 '21 at 10:04
  • @Enigmativity I have added the text of the problem, please see. – 1i10 Nov 27 '21 at 11:24
  • @1i10: There is nothing specific to SWI in your question, therefore the swi-prolog tag does not apply. – false Nov 29 '21 at 11:52
  • You've killed your question. Now any reader will be extremely confused as to how false even answered the question. You should put back what you just deleted, and then you should read [ask] and ensure you have provided us with a [mcve]. – Enigmativity Dec 01 '21 at 20:44

1 Answers1

2

The reason why your query fails is the following program fragment. I obtained it by systematically generalizing away goal after goal by adding a * in front. Because this fragment fails, also your original program will fail. I am sure it will be evident to you how to interpret this:

:- op(950, fy, *).      % auxiliary definition
*_.

:- initialization(guest(brown, _R, _T)). % your failing query

evidence(taylor,R,_):- *not(R=5).
evidence(white,R,_):- *not(R=5).
evidence(smith,R,_):- *not(R=1), *not(R=3), *not(R=6), *not(R=5).
evidence(green,R,_):- *not(R=3), *not(R=6).

guest(N,R,T):-
    *interrogation(N,R,T),
    evidence(N,R,T),
    *receptionist(N,R,T).

Just a remark, instead of not(A=B) rather use dif(A,B). It's the 21st century...

false
  • 10,264
  • 13
  • 101
  • 209
  • Do I understand correctly that I have to add the rules? For example, for the same brown: evidence (brown, _, _). Etc. Of course it's funny about "non". But this is how the teacher showed it))) – 1i10 Nov 27 '21 at 10:10
  • There is no `evidence/3` about `brown`. But according to your definition of `guest/3`, there has to be some evidence. – false Nov 27 '21 at 10:16
  • I have added the text of the problem, please see. – 1i10 Nov 27 '21 at 11:24