Use DCG Grammar rules to write the prolog predicate repeated(Count, Head, Tail)
. This predicate should be true if Head-Tail
is a difference list whos content is \(\texttt{a}^\texttt{Count}\texttt{b}^\texttt{Count}\texttt{c}^\texttt{Count}\). The predicate should be usable in 2 directions:
?- repeated(3,L,[]).
L = [a, a, a, b, b, b, c, c, c] .
?- repeated(Count,[a,a,b,b,c,c],[]).
Count = 2
It must also be possible to generate all solutions.
?- repeated(Count,L,[]).
Count = 0,
L = [] ;
Count = 1,
L = [a, b, c] ;
Count = 2,
L = [a, a, b, b, c, c] ;
Count = 3,
L = [a, a, a, b, b, b, c, c, c] ;
Count = 4,
L = [a, a, a, a, b, b, b, b, c|...] ;
Count = 5,
L = [a, a, a, a, a, b, b, b, b|...] ;
...