Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2023 Day 19 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team

Discussion thread for day 19 of the Advent of Code - https://adventofcode.com/2023/day/19

9 REPLIES 9
CoG
14 - Magnetar

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:

Spoiler
Part 1 is fairly straight forward. I used an iterative macro to track which rule a given part was working its way through (iterating on the entire list of parts). I used a Formula Tool with a lot of IIF's to handle the dynamic condition logic, generating all the output from each step of a rule (including Null() if a condition was not met). This allowed me to get the proper output by finding the first non-null value in the list of steps for a given rule. After the Iterative macro completed, all that's left to do is sum up all the values of all Accepted parts and your done!

Part 2 is where things get interesting. Brute force is (yet again) not feasible unless you can get your hands on a quantum computer and figure out how to build a workflow there. Since this is a counting problem, we can employ some basic principles of combinatorics and number theory. Namely, the total number of all possible independent variables is the product of all possible values for each variable. In this problem, if the only rule was in{A} then all parts are accepted by default with a total count of 4000*4000*4000*4000.

Naturally, we aren't that lucky, and so we must determine which ranges of values will be Accepted and which Rejected, working on a more granular scale, until we reach the end and can aggregate back to our answer and receive our sweet, sweet AoC star.

In order to keep track of ranges, we need a way of tracking them. I opted to track the Min and Max of each variable { 's', 'a', 'x', 'm' }, which used 8 columns, and lends itself to a very clear starting point for the nested iterative macro that will do the heavy lifting for us:
Min SMax SMin AMax AMin XMax XMin MMax MRule
14000140001400014000in

in order to evaluate and break down the ranges, I built a second nested iterative macro that iterates through the steps of a rule and determines which range of values satisfies the condition and which do not (those that do not will re-iterate until no range remains or the Else condition is reached).
Example Rule: in{ m < 2000:A, R }

Iteration 1: Matches values 'm' < 2000, which would output:
Min SMax SMin AMax AMin XMax XMin MMax MRule
14000140001400011999A

Leaving behind for the second and final iteration (Else condition):
Min SMax SMin AMax AMin XMax XMin MMax MRule
14000140001400020004000R

We would now have two records iterating through our outer macro, which would consequently end due to reaching A/R for all records.

Once the macros finish subdividing our ranges, we will be left with a list of range combinations that are either Accepted or Rejected. Filter for Accepted and Multiply the range for each individual variable (Max - Min + 1) * ...

Well Done if you managed to solve. These are tricky problems and can be challenging to wrap your head around!

Workflow:

Spoiler
Main:
_Main.png
Iterative Macro (Part 1):
_Part 1.png
Iterative Macro (Part 2):
_Part 2.png
Nested Iterative Macro (Part 2; separates ranges according to rules):
_Ranges.png

 

gawa
16 - Nebula
16 - Nebula

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

image.png

 

BTW, D19 was a bit tough one, but interesting. 

Spoiler
image.png
ScottLewis
11 - Bolide

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. 

 

Day19RangeSortMacro.PNG

Qiu
21 - Polaris
21 - Polaris

I know Dynamic Replace will be a good fit for the Criterias, but just have not made it working. 😁

phottovy
13 - Pulsar
13 - Pulsar

Fun challenge except I messed up the logic cleaning up my workflow to post 😅

 

Spoiler
19.png

Simply Outer Macro:
19 Macro1.png

Nested Macro:
19 Macro2.png
PangHC
12 - Quasar

think of range but still cant figure it. 

thanks @CoG 

 

Spoiler
similar concept. just less tools.

use multi-field tools to reduce the number of tools. but it may hard to understand by others.  
Screenshot 2023-12-20 132534.png
part2 macro
Screenshot 2023-12-20 132537.png
part2 macro's macro
Screenshot 2023-12-20 132609.png
include formula:
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

 

 

 

DaisukeTsuchiya
14 - Magnetar

P2 is difficult for me.

Spoiler
It took long time to make logic for P2. I recreate WF again and again and hought to quit many times.
Now it becomes fun and favorite problem once it is completed.
<Main WF>

スクリーンショット 2023-12-22 101459.png
<P1 Macro>

スクリーンショット 2023-12-22 101529.png
<P2 Macro>
スクリーンショット 2023-12-22 101549.png

AkimasaKajitani
17 - Castor
17 - Castor

This is needed the complex logic.

 

Spoiler

Part 1 macro : To simple the logic, I put the many macro input tools.
AoC_2023_19_02.png

Part 1 workflow.

AoC_2023_19_08.png
Part 2:

The start is only quize workflow.
AoC_2023_19_07.png

Based on that, I make the all pattern but not judge. To do this, I use the fowllowing macro.
AoC_2023_19_03.png

The result is as following. This is 1.

AoC_2023_19_09.png

Separately, I applied conditions to each tag. The first line is the same condition, but the next line reverses the condition. As you go down, the processing of the previous row is reversed, and further rows are stacked. Let's call this 2.

AoC_2023_19_12.png

AoC_2023_19_10.png

And then, I got all condition from 1 and 2.
AoC_2023_19_13.png
When I got the table bellow, it's like I got the answer.

 

AoC_2023_19_15.png

 




Final workflow:

AoC_2023_19_14.png

Tokimatsu
12 - Quasar

Long way to solve part2.  

Spoiler
スクリーンショット 2024-01-07 181526.png
Labels
Top Solution Authors