Hello,
I have a solution for the bridge crossing problem (4 people crossing a bridge with a time of 1,2,5,10 with a torch and they need to take the torch back as long as they didnt all crossed the bridge).
here is my code :
time(b,1).
time(e,2).
time(a,5).
time(l,10).
traverser(Tmax,[],MembresResDG,Temps,Transitions).
traverser(Tmax,MembresResGD,MembresResDG,Temps,Transitions):-
select(Me1,MembresResGD,MembresResGD1),
select(Me2,MembresResGD1,MembresResGD2),
append([Me1],MembresResDG,MembresResDG1),
append([Me2],MembresResDG1,MembresResDG2),
select(Me3,MembresResDG2,MembresResDG3),
append([Me3],MembresResGD2,MembresResGD3),
time(Me1,X),
time(Me2,Y),
time(Me3,Z),
NewTemps is Temps + max(X,Y) + Z,
NewTemps =< Tmax,
append(["Rive gauche : ", MembresResGD3," Rive Droite : ", MembresResDG3," Temps : ",NewTemps],Transitions,NewTransitions),
% write(NewTransitions),
traverser(Tmax, MembresResGD3, MembresResDG3, NewTemps,NewTransitions).
I don’t get why i cant get the solution.
Can anybody help ?