comp.lang.ada
 help / color / mirror / Atom feed
From: John Perry <john.perry@usm.edu>
Subject: Re: Advent of Code, Day 19
Date: Mon, 21 Dec 2020 15:45:53 -0800 (PST)	[thread overview]
Message-ID: <1e52d940-eb0c-4c13-a5cf-e3db46d4f0c0n@googlegroups.com> (raw)
In-Reply-To: <52690d99-a8ed-40c3-b3c3-8d54875506a5n@googlegroups.com>

On Monday, December 21, 2020 at 2:48:17 PM UTC-5, gautier...@hotmail.com wrote:
> For me the first part was the tough one.

I spent a while on the first one, partly because of that "Get" issue I referenced in another thread, but mostly because my brain wasn't working Saturday.

> 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. 

I used recursion from the beginning, but passing to the matching function the position of the last successful check, and returning the position of the "next" successful check. (With recursion, I mean "next recursive call", not "next linear rule". I hope you follow. This strategy worked just fine once 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 incorrectly. 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 evaluating 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 rather embarrassingly reasoned myself into knots trying to figure this out. I did 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 still 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 all 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; hopefully I don't regret saying this!

john perry

  parent reply	other threads:[~2020-12-21 23:45 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
2020-12-21 23:45     ` John Perry [this message]
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