这是我的作业线索:
四名司机:Norma、Andy、Edward 和 Olivia 被控四项交通违法行为:闯停车标志、超速、非法左转和闯红灯。使用线索找出每个嫌疑人违反了哪条法律。
线索
- 诺玛没有闯红灯或停车标志。
- 安迪从未因超速而被拦下。
- 爱德华非法左转。
- 奥利维亚总是小心翼翼地在停车标志前停下来。
我需要使用prolog来解决它。
到目前为止,我已经尝试了以下代码:
violatated(Violation):-
member(Violation,[speeding,leftturn,stop,red]).
solve(S):-
S=[[Name1,Violation1],
[Name2,Violation2],
[Name3,Violation3],
[Name4,Violation4]],
%five drivers: Norma, Andy, Edward, Olivia
Name1 = norma,
Name2 = andy,
Name3 = edward,
Name4 = olivia,
violated(Violation1), violated(Violation2), violated(Violation3), violated(Violation4),
Violation1 \== Violation2, Violation1 \== Violation3, Violation1 \== Violation4,
Violation2 \== Violation1, Violation2 \== Violation3, Violation2 \== Violation4,
Violation3 \== Violation1, Violation3 \== Violation2, Violation3 \== Violation4,
Violation4 \== Violation1, Violation4 \== Violation2, Violation4 \== Violation3,
%Edward made an illegal left turn
Violation3 == leftturn,
%Norma did not run either a red light or a stop sign
Violation1 \== red,
Violation1 \== stop,
%Andy was never stopped for speeding.
Violation2 \== speeding,
%Olivia was always careful to stop at a stop sign
Violation4 \== stop.
对不起,我是prolog的新手!