OK, here's the question:
Give a DCG that generates the set of strings w?{0,1}* with the same number of 0's as 1's so that, for example
?- s([0,1,1,0],[]).
yes
?- s([0,0,1,1,],[]).
yes
?- s([1,1,0,1,0],[]).
no
Now, my program is this:
s--> [].
s--> z,s,o,s.
s--> o,s,z,s.
z--> [0].
o--> [1].
My problem is this:
I was told this wasn't right, that it wouldn't work for all cases, but I've checked loads of examples and it works for all of them. Can someone tell me what I'm doing wrong? I'm new to programming so I might be doing something totally stupid...forgive me if I am
Give a DCG that generates the set of strings w?{0,1}* with the same number of 0's as 1's so that, for example
?- s([0,1,1,0],[]).
yes
?- s([0,0,1,1,],[]).
yes
?- s([1,1,0,1,0],[]).
no
Now, my program is this:
s--> [].
s--> z,s,o,s.
s--> o,s,z,s.
z--> [0].
o--> [1].
My problem is this:
I was told this wasn't right, that it wouldn't work for all cases, but I've checked loads of examples and it works for all of them. Can someone tell me what I'm doing wrong? I'm new to programming so I might be doing something totally stupid...forgive me if I am