Discussion thread for day 19 of the Advent of Code - https://adventofcode.com/2023/day/19
This problem was a ton of fun, especially Part 2. It seems I really enjoy working with ranges (it's like generating a spider's web). At first, I was intimidated by Part 2, but once I got into the flow and started putting things together, it all came together beautifully (I didn't even have to debug Part 2's workflow at all)!
I will post my exported workflow later
Edit: Added my workflow
Algorithm:
Min S | Max S | Min A | Max A | Min X | Max X | Min M | Max M | Rule |
1 | 4000 | 1 | 4000 | 1 | 4000 | 1 | 4000 | in |
Min S | Max S | Min A | Max A | Min X | Max X | Min M | Max M | Rule |
1 | 4000 | 1 | 4000 | 1 | 4000 | 1 | 1999 | A |
Min S | Max S | Min A | Max A | Min X | Max X | Min M | Max M | Rule |
1 | 4000 | 1 | 4000 | 1 | 4000 | 2000 | 4000 | R |
Workflow:
I realized I frequently switch sample<=>input data, and to do so, disconnect and connect the line again and again. As I'm tired of this process, created switching macro as attached. If you feel the same thing, please use it.(I cannot take responsibility if you have wrong answer by some error of this macro😅 believe it does not...
BTW, D19 was a bit tough one, but interesting.
Liked this one because it made me think about how I build.
This is really just case management and string parsing, excepting that it is hard versions of both those things.
For case management problems I like to build in an inefficient way. Rather than trying to manage cases in formulas or collapse them into macros I lay out branching paths and fill them in as the cases occur in the data and then eventually once I can see all the patterns fill in the rest. I do a lot of copy/paste and simple formula edits (simple because of consistent field names.) The end result is something like the part2 (RangeSort) Macro. If I was going to put something like this into production I would look at collapsing some of the paths and likely writing a second tier macro that did a single rule without having to know where it was in the instruction but for prototyping (which is really what advent is) I prefer to forgo inefficiency. As a bonus you end up with beautifully monstrous workflows.
Also an interesting window into how much efficiency increases when you're not watching a workflow run. My part 2 runs for a bout 3 seconds to do the third iteration. If I instead run the whole of part 2 from the main workflow the macro runs every iteration in less than a second.
I know Dynamic Replace will be a good fit for the Criterias, but just have not made it working. 😁
Fun challenge except I messed up the logic cleaning up my workflow to post 😅
think of range but still cant figure it.
thanks @CoG
if right([_CurrentFieldName_],1)=[variable] then
if [operator]=">" then
if contains([_CurrentFieldName_],"Min") then
[amount]+1
else
[_CurrentField_]
endif
elseif [operator]="<" then
if contains([_CurrentFieldName_],"Max") then
[amount]-1
else
[_CurrentField_]
endif
else
[_CurrentField_]
endif
else
[_CurrentField_]
endif
exclude/ else formula
if right([_CurrentFieldName_],1)=[variable] then
if [operator]="<" then
if contains([_CurrentFieldName_],"Min") then
[amount]
else
[_CurrentField_]
endif
elseif [operator]=">" then
if contains([_CurrentFieldName_],"Max") then
[amount]
else
[_CurrentField_]
endif
else
[_CurrentField_]
endif
else
[_CurrentField_]
endif
P2 is difficult for me.
This is needed the complex logic.
Part 1 workflow.
Based on that, I make the all pattern but not judge. To do this, I use the fowllowing macro.
The result is as following. This is 1.
And then, I got all condition from 1 and 2.
Final workflow:
Long way to solve part2.