This was another interesting word puzzle I came across that I thought might be an interesting problem to solve:
Nine friends, looking for adventure, decided to race down a nearby highway. They had three cars: a Ferrari, a Mercedes, and a BMW. They divided themselves into three groups of three each. A destination was identified and they started the race.
One car had an accident. Another car had an engine failure. Only the third car managed to reach the destination.
Based on the above information, which friends were in which car and how did the each car perform in the race?
Regardless of who won the race, they certainly had very silly names!
Now for the interesting part, the Prolog solution:
Nine friends, looking for adventure, decided to race down a nearby highway. They had three cars: a Ferrari, a Mercedes, and a BMW. They divided themselves into three groups of three each. A destination was identified and they started the race.
One car had an accident. Another car had an engine failure. Only the third car managed to reach the destination.
- Okum, Olfum, and Ogum were not in the Mercedes. Also, all three were not in the same car.
- Ofrum was not in the car that had the accident.
- Obum and Okum were in the same car. It was not the one that had engine failure.
- Ovum, whose car didn't have an accident, was not in the same car as either Ogum or Okum.
- Ogum was in the BMW along with Oskum.
- Opum and Odum were in the same car. It was not the one that had engine failure.
Based on the above information, which friends were in which car and how did the each car perform in the race?
Regardless of who won the race, they certainly had very silly names!
Now for the interesting part, the Prolog solution:
Sol = [[merc, [ovum, opum, odum], success], [ferrari, [okum, olfum, obum], accident], [bmw, [ogum, ofrum, oskum], engine]]
Translated into english as follows:
- Ovum, Opum and Odum finished the race in their Merc.
- Okum, Olfum and Obum crashed their Ferrari.
- Ogum, Ofrum and Oskum broke down in their BMW.
The code listing below finds the solution.
not(Thing) :- call(Thing),!,fail.
not(Thing).
start(Sol):- Sol=[[merc,Mpeople,_],[ferrari,Fpeople,_],[bmw,Bpeople,_]],
Mpeople=[_,_,_],Fpeople=[_,_,_],Bpeople=[_,_,_],
member([_,Apeople,accident],Sol),
member([_,Epeople,engine],Sol),
member([_,Speople,success],Sol),
(member(okum,Mpeople);member(okum,Fpeople);member(okum,Bpeople)),
(member(olfum,Mpeople);member(olfum,Fpeople);member(olfum,Bpeople)),
(member(ogum,Mpeople);member(ogum,Fpeople);member(ogum,Bpeople)),
(member(obum,Mpeople);member(obum,Fpeople);member(obum,Bpeople)),
(member(ovum,Mpeople);member(ovum,Fpeople);member(ovum,Bpeople)),
(member(opum,Mpeople);member(opum,Fpeople);member(opum,Bpeople)),
(member(ofrum,Mpeople);member(ofrum,Fpeople);member(ofrum,Bpeople)),
(member(odum,Mpeople);member(odum,Fpeople);member(odum,Bpeople)),
(member(oskum,Mpeople);member(oskum,Fpeople);member(oskum,Bpeople)),
not(member(okum,Mpeople)), not(member(olfum,Mpeople)), not(member(ogum,Mpeople)),
not((member(okum,Bpeople),member(olfum,Bpeople),member(ogum,Bpeople))),
not((member(okum,Fpeople),member(olfum,Fpeople),member(ogum,Fpeople))),
not(member(ofrum,Apeople)),
(member(Somepeople,[Apeople,Speople]), member(okum,Somepeople), member(obum,Somepeople)),
not(member(ovum,Apeople)),
not((member(Somepeople1,[Speople,Epeople]),member(ovum,Somepeople1),member(ogum,Somepeople1))),
not((member(Somepeople2,[Speople,Epeople]),member(ovum,Somepeople2),member(okum,Somepeople2))),
member(ogum,Bpeople),
member(oskum,Bpeople),
(member(Somepeople3,[Apeople,Speople]), member(opum,Somepeople3), member(odum,Somepeople3)),
!.
No comments:
Post a Comment