Hello swi-prolog,
Thank you in advance for your time and advice.
I have been tasked to write a single predicate and single rule prolog that takes in a list and find if it have 3 items in decreasing by order of 2. true if it does and false if not.
My single predicate and single rule:
three_by_two([A, B, C | T]) :- B is C - 2, A is B - 2, three_by_two([B, C | T]).
Tests:
three_by_two([1, 10, 5, 3, 42, 23, 5]). %“false”
three_by_two([5, 23, 42, 3, 5, 10, 1]). % “true, for [5, 3,1].”
During trace, I see that the predicate and rule is not performing the rule through all the elements of the list. Kindly requesting guidance and direction as to how to properly solve the problem and understand the solution.
Allowed constructs:
1.“is”
2.“-”
3.“:-”
4.“,”
5.“;”
6. “”
7.“[H|T]”
8. “!”
Thank you,
hcxs