Rules: no spoilers.

The other rules are made up as we go along.

Share code by link to a forge, home page, pastebin (Eric Wastl has one here) or code section in a comment.

  • @swlabr
    link
    English
    39 months ago
    1. After this problem, I will create a new reply in the OP if it is not there already, and will discuss under that thread.
    a,b

    So, like many other problems from this year, this is one of those direct solution problems where there isn’t much of a neat trick to getting the answer. You just have to implement the algorithm they specify and hope you can do it correctly.

    a) I used a regex to do some parsing because I haven’t looked at dart regex much and wanted to dip my toes a little.

    I considered doing this “properly” with OO classes and subclasses for the different rules. I felt that it would be too difficult and just wrote something janky instead. In hindsight, this was probably the wrong choice, especially since grappling with all the nullable types I had in my single rule class became a little too complex for my melting brain (it is HOT in Australia right now; also my conjunctivae are infected from my sinus infection. So my current IQ is like down 40 IQ points from its normal value of probably -12)

    b) There may have been a trick here to simplify the programming (not the processing). Again, I felt that directly implementing the specified algorithm was the only real way forward. In brief:

    1. Start with an “open” set containing a part with 4 ranges from [1, 4001) and an “accepted” set that is empty.
    2. Start at the workflow “in”
    3. For each rule in the current workflow:
    • If the rule accepts part of the ranges in the open set, remember those ranges in a closed set and remove them from the open set.
    • Remove anything the rule rejects from the open set.
    • If the rule redirects to a different workflow W, split off the applicable ranges and recurse at 3 with the current workflow as W.
    • Keep in the open set anything the rule doesn’t consider.

    Because this is AOC, I assumed that the input would be nice and wouldn’t have anything problematic like overlapping ranges, and I was right. I had a very stupid off by one error that took me a while to find as well.

    The code I have up as of this comment is pretty long and boring, I might try clean it up later.

    • @swlabr
      link
      English
      39 months ago

      update: have cleaned up the code.

    • @zogwarg
      link
      English
      39 months ago

      Replying in OP: Yeah, Lemmy punishes old threads/posts a bit too much for my taste ^^.

      • @swlabr
        link
        English
        39 months ago

        Good note for next year!