[m-users.] Avoiding a segmentation violation caused by a DCG

Razetime <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <CAMtxHUsKrsT1cMcOcP8Wuo_8GCWxFU6MxMGzhtwXbhro1P=bWQ@mail.gmail.com>
I am trying to make a DCG that solves part of of advent of code 2016
day 9: https://adventofcode.com/2016/day/9

The code I have so far is here:
https://github.com/razetime/aoc/blob/main/16/a09.m

pattern/3 takes a character list and checks if it matches

(<numberA>x<numberB>)<A*B characters>

substNxN consumes a single alphabet character, adding 1 to the length
until a different replaceable pattern is reached.

My problem here is that the test code

https://github.com/razetime/aoc/blob/main/16/inp/09

works fine, returning the final length of all the given input, but the
larger test case

https://github.com/razetime/aoc/blob/main/16/inp/09

fails. After debugging I think this is due to a stack overflow.

My assumption was that I could make this DCG tail recursive, or use
semicontext notation to pass the final length through the states. How
can I resolve this problem?
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.