%% Measure distance the javelin is thrown %% ?- distance([' ', ' ', ' ', '.'], Distance). %% Distance = 3 ; distance(Units, Distance) :- distance(Units, 0, Distance). distance(['.'], Distance, Distance). distance([' ' | Units], Distance1, Distance2) :- Distance3 is Distance1 + 1, distance(Units, Distance3, Distance2). %% Objection: Lever breaks %% ?- sound(strong, heavy, [[0, weak, light], [1, 'medium-strength', 'medium-weight'], [2, strong, heavy]], Sound). %% Sound = 1 ; sound(Strength, Weight, Thresholds, Sound) :- soundness1(Thresholds, Weight, Soundness1), soundness2(Thresholds, Strength, Soundness2), compare2(Soundness1, Soundness2, Sound). soundness1(Thresholds, Weight, Soundness) :- member(Threshold, Thresholds), Threshold = [Soundness, _Strength, Weight]. soundness2(Thresholds, Strength, Soundness) :- member(Threshold, Thresholds), Threshold = [Soundness, Strength, _Weight]. compare2(Soundness1, Soundness2, 0) :- Soundness1 >= Soundness2. compare2(Soundness1, Soundness2, 1) :- Soundness1 < Soundness2.