comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Advent of Code, Day 19
Date: Mon, 21 Dec 2020 21:38:12 +0100	[thread overview]
Message-ID: <rrr13m$lis$1@dont-email.me> (raw)
In-Reply-To: <52690d99-a8ed-40c3-b3c3-8d54875506a5n@googlegroups.com>

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

  reply	other threads:[~2020-12-21 20:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-19 13:43 Advent of Code, Day 19 Gautier Write-Only Address
2020-12-20  1:01 ` John Perry
2020-12-21 19:48   ` Gautier Write-Only Address
2020-12-21 20:38     ` Jeffrey R. Carter [this message]
2020-12-21 23:45     ` John Perry
2020-12-22 16:43       ` Maxim Reznik
2020-12-23  0:57         ` John Perry
2020-12-24 11:55           ` Maxim Reznik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox