Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DCG Problem

Status
Not open for further replies.

scolarda

Programmer
Dec 7, 2010
1
0
0
IE
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 :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top