From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Advent of Code, Day 19 Date: Mon, 21 Dec 2020 21:38:12 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <52690d99-a8ed-40c3-b3c3-8d54875506a5n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 21 Dec 2020 20:38:15 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="f23688ce941d4032ce24ef8bd533851a"; logging-data="22108"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bUjunAmQRBNqI69v88a59Zru5erxbMYQ=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 Cancel-Lock: sha1:DQ9XKy/l+ek+TSSPynnCNnzGHHg= In-Reply-To: <52690d99-a8ed-40c3-b3c3-8d54875506a5n@googlegroups.com> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:60916 List-Id: On 12/21/20 8:48 PM, Gautier Write-Only Address wrote: > For me the first part was the tough one. I've tried for too long to structure the rules verification like this > procedure Verify_Rule (...) is > ... > procedure Verify_Rule_List (...) is > ... > begin > loop on the list, call recursively Verify_Rule > end; > end; > But a loop cannot be used here, each subrule can consume a variable range of characters in the string and there are multiple tails of the string for the next subrule for the loop. > So the solution in that case was to delegate everything further to recursion. I initially thought of it as similar to a regular expression, since a single rule could end up matching many characters. I therefore reviewed PragmARC.Matching.Regular_Expression to see how it might be modified for this problem. That led me down the wrong path, as these are more recursive rewriting rules than regular expressions. Once I realized that I soon found a simple recursive solution probably similar to yours. > if part = 2 then > rule (8) := (is_terminal => False, max => 3, alt => 2, sub => (42, 42, 8, -1, -1)); > rule (11) := (is_terminal => False, max => 5, alt => 3, sub => (42, 31, 42, 11, 31)); > end if; I copied and modified the input file, and modified the program to allow a rule list to have up to 3 rules. My structure for a rule was somewhat more complex than yours, following a semi-formal description of the structure of the data. -- Jeff Carter "It has been my great privilege, many years ago, whilst traveling through the mountains of Paraguay, to find the Yack'Wee Indians drinking the juice of the cacti." The Old Fashioned Way 152