[m-users.] Problem with DCG producing false negative
Mark Brown
mark at mercurylang.org
Mon Oct 17 21:47:09 AEDT 2022
On Mon, Oct 17, 2022 at 5:44 AM Razetime <rraghu.11502 at gmail.com> wrote:
>
> I have created the following predicate tls to match lines that satisfy
> the conditions given in Advent of Code Day 7:
> https://adventofcode.com/2016/day/7 (Spoilers)
>
> For some reason during testing ,the DCG fails when given
> L="fslvgbiibdkhchajyb[zpbhqrokrbfuqrowop]gqqzoqvfsdfcjcdurrs[xhqfcfytbbekivnvod]jxjwuxivnyhppvfhaol[evfnrmrjnnhychtpv]emiyjcjsnojxexs",
> tls(X,Y,to_char_list(L),[])
> and I am not sure why it is giving that result. What is done wrong here?
I can see one clause that is most likely incorrect, but it depends on
your intended meaning for tls/4.
Perhaps you can state the intended meaning, that is, the relationship
you want to hold between the four arguments of tls? (The other
predicates are clear enough.) Then we may be able to explain the
unexpected result.
Mark
>
> :- pred tls(list(cl)::out,list(cl)::out,cl::in,cl::out) is nondet.
> tls([X],[]) --> {alp(X)},seq(X).
> tls([X0|X],[Y0|Y]) --> {alp(X0),alp(Y0),\+abba(Y0)},
>
> seq(X0),['['],seq(Y0),[']'],tls(X,Y),{any_true(abba,[X0|X])}.
>
> :- pred seq(list(T),list(T),list(T)).
> :- mode seq(out,in,out) is multi.
> seq([]) --> [].
> seq([E|Es]) --> [E], seq(Es).
>
> :- pred alp(cl::in) is semidet.
> alp(L):-all_true(is_alpha,L).
>
> :- pred abba(cl::in) is semidet.
> abba([A,B,B,A|L]):-A\=B.
> abba([_,A,B,C|L]):-abba([A,B,C|L]).
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org
> https://lists.mercurylang.org/listinfo/users
More information about the users
mailing list