Ritta Neg-Mfa
Ritta Neg-Mfa

Reputation: 1

how can i solve the prolog puzzle below?

Quiz Quest:

There has been a keenly fought quiz among five teams. The losers did not quite live up to their name and finish fourth. The numbskulls were not the team who took movies as a special subject. The team answering questions on cookery finished directly above the team called the garden gang who in turn were directly above the team specializing in history, only the pop music specialists Finished above the Rhubarb pickers . The heavy Mob were two positions below the team answering about current affairs. which team specialized in which subject and where did they all finish?

Solution | Quiz Quest :

Numbskulls, pop music , first.
Rhubarb Pickers, cookery ,second
Garden gang , current affairs , third.
Heavy mob movies , fifth
The losers , history , fourth.

Full Solution | Quiz Quest :

Rhubarb Pickers a second , the losers fourth the team who took cookery have two teams directly below them. They cannot be first , pop music , so must either be second or third . if they were third then the garden gang would be fourth, but The losers are fourth so cookery was answered by the team, finishing second which was Rhubarb Pickers , with Garden gang third and the losers matched with history. Heavy Mob must be last as they were two positions below the current affairs specialist who must be the garden gang . Numbskulls must be first , and the last team answered the movie questions.

Do not use any Prolog predicates other than append/3, dif/2, and member/2.

"There has been a keenly fought quiz among five teams." (Transcript continues in starter code comments.) "Which team specialized in which subject and where did they all finish?"

When you have correctly programmed the given facts and consulted your program, you should be able to make the following query:

?- quiz_quest(Teams).
Teams = [(numbskulls, pop_music), (rhubarb_pickers, cookery), (garden_gang, current_affairs), (losers, history), (heavy_mob, movies)] ;
false.

quiz_quest(Teams):-
   Teams = [ % (Name, Subject) -- position in list is rank, first to last
       (numbskulls, pop_music),
       (rhubarb_pickers, cookery),
       (garden_gang, current_affairs),
       (losers, history),
       (heavy_mob, movies)
   ],

% "The losers did not quite finish up to their name and finished fourth".
   append(_, [(losers, history) | _], Teams),

% "The numbskulls were not the team who took movies as a special subject".
   \+ member((numbskulls, movies), Teams),

%" The team answering questions on cookery finished directly above the team called the garden gang".
% "The garden gang were directly above the team specializing in history".
   append(_, [(cookery, _), (garden_gang, _), (history, _) | _], Teams),

% Only the pop music specialists finished above the Rhubarb Pickers.
   append(_, [(_, pop_music), (rhubarb_pickers, _) | _], Teams),

% The heavy Mob were two positions below the team answering about current affairs.
   append(_, [(_, current_affairs), (_, _), (heavy_mob, _) | _], Teams).

i am supposed to get

   Teams = [(numbskulls, pop_music), (rhubarb_pickers, cookery), (garden_gang, current_affairs), (losers, history), (heavy_mob, movies)] ;
   false.

as my output but i get only false . i dont know what the problem could be.

Upvotes: 0

Views: 97

Answers (0)

Related Questions