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

Razetime rraghu.11502 at gmail.com
Wed Oct 19 13:33:28 AEDT 2022


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?


More information about the users mailing list