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=0.8 required=3.0 tests=BAYES_50 autolearn=ham autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:ad4:4083:: with SMTP id l3mr19404033qvp.17.1608594354154; Mon, 21 Dec 2020 15:45:54 -0800 (PST) X-Received: by 2002:aed:2c25:: with SMTP id f34mr18862607qtd.346.1608594354038; Mon, 21 Dec 2020 15:45:54 -0800 (PST) Path: eternal-september.org!reader02.eternal-september.org!feeder1.feed.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 21 Dec 2020 15:45:53 -0800 (PST) In-Reply-To: <52690d99-a8ed-40c3-b3c3-8d54875506a5n@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=107.88.177.42; posting-account=JSxOkAoAAADa00TJoz2WZ_46XrZCdXeS NNTP-Posting-Host: 107.88.177.42 References: <52690d99-a8ed-40c3-b3c3-8d54875506a5n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <1e52d940-eb0c-4c13-a5cf-e3db46d4f0c0n@googlegroups.com> Subject: Re: Advent of Code, Day 19 From: John Perry Injection-Date: Mon, 21 Dec 2020 23:45:54 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:60919 List-Id: On Monday, December 21, 2020 at 2:48:17 PM UTC-5, gautier...@hotmail.com wr= ote: > For me the first part was the tough one. I spent a while on the first one, partly because of that "Get" issue I refe= renced in another thread, but mostly because my brain wasn't working Saturd= ay. > 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.=20 I used recursion from the beginning, but passing to the matching function t= he position of the last successful check, and returning the position of the= "next" successful check. (With recursion, I mean "next recursive call", no= t "next linear rule". I hope you follow. This strategy worked just fine onc= e I stomped out the bugs introduced for the aforementioned brain failures. What hung me up on the second part was that I handled the rule options inco= rrectly. I didn't think to check all the options; if one of them worked, I = figured it was true, so returned only the position of the first successful = option! That fails once the loop is introduced: "8: 42 | 8 42" may succeed at evalu= ating rule 8 with option "42", but that position fails with rule 11 (from "= 0: 8 11"). The code wasn't checking "8 42", because "8" had worked. I rathe= r embarrassingly reasoned myself into knots trying to figure this out. I di= d eventually work out a complicated fix, but didn't implement that one. Peeking at your solution broke the logjam: check "42", then "8 42". I was s= till stuck because of the double positions (you have a different approach I= believe; you return True or False) and finally I realized I could return a= ll the positions that work. Correctness of the entire string comes from one= of the returned positions being S'Length + 1. I was rather pleased when it= finally worked out. I've looked at Part 1 of Day 20 & that doesn't seem nearly as hard; hopeful= ly I don't regret saying this! john perry