I want to program a list that uses only the characters {a, b}.
My objective is that prolog returns true only if the list that the user enter contains n number of a, or at least one a but has to finish with one b only, no more and no less than just one b.
Example: aaab
is correct, aba
is incorrect, a
is incorrect, b
is incorrect and the list empty which is [] is also correct.
Here’s my code :
langage([]).
langage([a | S]) :-
langage(S).
The problem here is that it only accepts n numbers of a, and does not finish with b. But I want it to finish with the letter b.
I hope someone can help me.
Edit by @EricGT
This is cross posed on StackOverflow (ref)