confusedstudent1
Programmer
- Dec 3, 2010
- 3
I have to write a DCG that generates strings from the alphabet a E {0,1,2} the strings have to have the form nn. This means queries like ?- s([0,2,1,0,2,1],[]). and s([1,1,2,0,1,1,2,0],[]). would return true.
This is the code I have so far. I'm so close. Can someone help me further?
s --> s(X), s(X).
s --> [].
s(0) --> zero, s(X).
s(1) --> one, s(X).
s(2) --> two, s(X).
s(3) --> [].
zero --> [0].
one --> [1].
two --> [2].
Many thanks
This is the code I have so far. I'm so close. Can someone help me further?
s --> s(X), s(X).
s --> [].
s(0) --> zero, s(X).
s(1) --> one, s(X).
s(2) --> two, s(X).
s(3) --> [].
zero --> [0].
one --> [1].
two --> [2].
Many thanks