Important Community update: The process for changing your account details was updated on June 25th. Learn how this impacts your Community experience and the actions we suggest you take to secure your account here.

General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2023 Day 13 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team

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

12 REPLIES 12
AndrewDMerrill
13 - Pulsar

Lots of Tools turned into Lots of Macros (Standard). Good problem involving lots of data manipulation. Felt like I was exercising my math muscles quite a bit throughout this challenge! (Still intend to wait until Top 10-15 have finished the D13P2 before I post my .yxzp)

Algorithm:

Spoiler
First, I will say that the problem confused me in that I thought every matrix had both a vertical and horizontal reflection line. This is incorrect. Each matrix from your input will have either a vertical or a horizontal reflection line (not both). You may not have been confused by this, but I sure was!

This problem relies on a subtle trick that turns the challenge into a fairly simple comparison. My approach was to leverage the power of Alteryx in handling row operations to compute a horizontal reflection line only (this allows us to limit string operations and reduces headaches). The workflow handles vertical reflection with the insight that a vertical reflection in a matrix M is the same as the horizontal reflection in the transpose of that same matrix:
#..#
....
^ has vertical reflection with 2 rows to the left. After Transpose:
#.
..
..
#.
^ now has horizontal reflection with 2 rows above.

Armed with this knowledge, we can now think through how to check all potential reflection lines in a matrix. The method is actually quite interesting. If you think about it, in order for a reflection to be valid (remember we only care about horizontal), the rows from top -> bottom and bottom -> top should be the same or, in other words the reflection about the center point should be the same (obviously), but what about the rest of the matrix? Conceptually, there is no reason to just ignore/drop the rest of the matrix. When we do this, however, we learn that all of the possible reflection lines can be computed by essentially running a "Convolution" of the matrix against its horizontal reflection:
_Explanation.png
Performing this Convolution is where the power of Alteryx works like a charm. For every matrix, after flipping it upside-down (Sort descending and re-index) we can use the Generate Rows Tool to generate a [Row Offset], which will create all the copies of the matrix that we need that we can Join on [Row] = [Reflection Row] + [Row Offset] to get all sub-Matrices corresponding to all horizontal reflections. Now all we need to do is figure out which one of these sub-Matrices has equal rows (since we Joined on the reflection, we only need to compute row level equality M1:row_i = M2:row_i). We can then work backwards from the Row Offset that has all matches to figure out how many rows are above.

All in all, I thought this was a fun problem with good opportunities for learning. This explanation lacks a few details here and there, but those are left as an exercise for the reader to solve. Happy Solving!!!

(P.S. as a corollary, P2 is solved in exactly the same way, except for key difference, you aren't looking for complete match, rather you need to be exactly 2 rows short of a perfect match (2 rows since we are dealing with symmetry of reflection). Of those near misses, you can do a cell by cell comparison to see which sub matrices differ in exactly 2 places (again due to reflection symmetry). Everything else is the same as in P1.)

 

Workflow:

Spoiler
Main Workflow:
Spoiler
Main Workflow.png

Calculate Macro (Part 1):
Spoiler
Calculate.png

Calculate 2 Macro (Part 2):
Spoiler
Calculate2.png

Calculate Prep Macro:
Spoiler
Calculate Prep.png

Transpose Matrix Macro:
Spoiler
Transpose Matrix.png

Edit: Solution is now posted!

 

kelsey_kincaid
12 - Quasar

I was pretty happy not to have to use any macros in Part 1, though I opted to create a standard macro. Part 2 is a different story. I wayyyy overcomplicated part 2 in an effort to move quickly rather than spend time optimizing, and ended up with a standard macro inside of an iterative macro inside of a batch macro. Probably could have skipped the batch macro at the very least. I should just change my name to "brute force" at this point.

 

Do I love my solution? Not really, but it works and this one doesn't seem as fun to clean up as some of my others. Curious to see what everyone else does, though.

 

 

Spoiler
Workflow:
D13.pngStandard Macro for Checking Mirror Placements:
D13 Std.png
Batch Macro for No Good Reason w/ Iterative Macro Embedded:
D13 Batch.png
Iterative Macro w/ Standard Macro embedded to check smudges:
D13 Iter.png

 

 

Pang_Hee_Choy
12 - Quasar

good one. spend lot of time to find the correct way.

 

Spoiler
1. generate grid, create 2 group, by x and by y
2. do the comparison
3. found, then output (I guess it have only once.)
4. calculate point as request

workflow
Screenshot 2023-12-13 164315.png
part1 macro
Screenshot 2023-12-13 164320.png

Part2
1. change each value, run part one macro again. (so, 3x3 map will run 9 iteration)
2. because only got one to change, so you will see there have a result is repeat once (i.e. 2, another 1 is when you change another side),
    and other (i.e. more than 2, as the changed is not in reflection)
3. filter for result count is 2 and calculate the score as part1. 

note: make sure you go through whole map, did not stop once found.
 
part2 macro:
Screenshot 2023-12-13 164331.png
AkimasaKajitani
17 - Castor
17 - Castor

I went to the Iterative macro route. I think that Day12 hit me and I can not completely change from the macro curse. But it works quickly. It took only1.5 seconds for part 1 and 2.

 

Spoiler
AoC_2023_13_9.png
The basic way is the same between part1 macro and 2 macro. The Part 2 macro can also output the Part 1 answer by simply erasing only two letters.

Part 1 macro
AoC_2023_13_4.png
My compared way is as follows.
AoC_2023_13_2en.png

=> The mirror position is no "Not match".



Part 2 macro
When the compared strings are taken apart and matched, the answer is only the one letter less than full set. At the above screenshot, I separated Input column to each letter and count Match. If the length of Input -1 is the number of the Match , it is mirror position.
AoC_2023_13_6.png

mmontgomery
11 - Bolide

P1 was fast to run but took me a while to set up. P2 in spoiler

Spoiler
P1 logic was to compare the whole row to the whole row or the whole column to the whole column and it ran fast.

P2 took the elements of P1 and put them in an iterative macro that unioned the row/column logic while testing the values spit out from P1.

Finally, I took a batch macro and wrapped it around the macro to make sure it looped through each collection until done.

One of my records needed a manual fix based on my macro output. I did the 'eye' test to grab it and be on our way! d13P1_Imacro.pngd13P1_Whole.pngd13P1_Batch.pngd13P1.png
patrick_digan
17 - Castor
17 - Castor

I felt pretty good about this one. No macro and quickly got part 2.

Spoiler
I just took each point and tried all the different possible translations for part 1 by using a couple generate rows, one for horizontal and another for vertical. For each pattern, I then summed up all the possible matches vs how many actually matched. Then for part 2, all I had to do was find patterns where the actual matches were 2 less than the total possible matches.
image.png
phottovy
13 - Pulsar
13 - Pulsar

Finally got P2 thanks to @Pang_Hee_Choy helping me understand the final steps I was missing!

 

 

Spoiler
Main Workflow:
13.png

P1 Macro:
13_M1.png

P2 Macro (which uses P1 Macro):
13_M2.png

 

 

DaisukeTsuchiya
13 - Pulsar

I enjoyed D13.

 

 

Spoiler

Brute force approach works and WF runs in 10 sec.

スクリーンショット 2023-12-14 084020.png

<Common Macro for P1 and P2>

スクリーンショット 2023-12-14 080232.png

<P2 Macro>
スクリーンショット 2023-12-14 080350.png

ApekshaSharma
6 - Meteoroid
Spoiler

Day 13 gave me some hope after Day 12 P2

Below is my approach for Day13 P2 which is inclusive of the logic used for P1

First, I split all characters in each pattern and assigned pattern id, row id & column id to each of them.

id.png

Then, I identified which rows and columns were almost equal to each other if not for the 'smudge'.

Compare almost equal rows.png
I used this to identify what were my potential smudges for each pattern.
Potential Smudges.png
Then, I passed each potential smudge through an iterative macro where I replaced the original character with my smudge and ran it through my part 1 logic.

Update Smudge.png
To identify the perfect mirror, I first identified the set of equal rows and columns.

Identify equal rows &  columns.png

If the equal pairs were just next to each other I labeled them as potential mirrors and generated the full set of pairs needed for each potential mirror for it to be a perfect reflection.
Generate possible mirror Ids .png
Then I checked each potential mirror with the available equal pairs to determine whether it is a valid mirror.

Miorrors that match criteria.png

Passed the pattern summary for each potential smudge to the macro output.
Output pattern summary for each smudge.png
Finally, removed any original mirrors from my output. 

remove original mirrors.png
Labels