General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2023 Day 10 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team

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

22 REPLIES 22
AndrewDMerrill
13 - Pulsar

Cool problem, good applications from Graph theory. Kind of "cheated" (brute forced/found a pattern in the data) to speed up initial solving time. Then went back and improved the Workflows to make them more generalized.

 

What follows is the algorithm I used in addition to pictures of my workflows (read at your own risk)

Spoiler
For part 1, it is assumed that the point S has exactly 2 connections (otherwise the loop wouldn't quite be continuous and you risk creating multiple interior points, which would make Part 2 much more difficult). Thus we simply need to find which neighbors of S could be connected (example: The only pipes that would be valid connections to the left of S are ("-", "F", "L")). By finding these 2 connections, I figured it would be simpler to trace the entire path than traverse both sides until I met back at the opposite side, so I select only one connected neighbor (doesn't matter which), keep track of which direction the pipe is moving, and then traverse the entire loop of pipe until I return to S. The answer to part 1 is however many pipes we went through along the way divided by 2 (It is a fun and simple challenge to show that for a grid setup like this, the total path length will always be even).

For part 2, we now make use of some data we collected as the loop of pipe was discovered, namely whether we turned left, right, or not at all (denoted -1, 1, 0, respectively). The trick here is that if you add all the turn values together, you can determine which side of the loop of pipe the interior is on since the interior will always be on the same side as the loop is traversed (To better understand this principle: imagine standing at the edge of a swimming pool such that the pool is to your right. If you then begin walking all around the pool to get back where you started, the pool will always be to your right). The reason that the sum of all the turn values allows you to know which side of the path is the interior is that in order to walk around the interior of a loop, you will necessarily have to turn more in the direction of the interior than you do away from it. Simplifying the pool example, imagine you stand next to a square pool with the water on your Right. Walking around the pool, you will have turned Right 4x before returning to the start.

Now that you know which side of the loop the interior is on, you can determine which interior points are immediate neighbors pipes in the loop and then do what is essentially a Breadth First Search (BFS) of all of those points to get all interior points of the loop. The count of those points should give you your answer.

Workflow:
Screenshot Main Workflow.png
Build Pipe Loop Macro:
Screenshot First Macro.png
Find Interior Points Macro:
Screenshot Interior Points Macro.png
kelsey_kincaid
12 - Quasar

Coordinates always trip me up, but I am proud of my part 2 solution which I was able to accomplish in a few tools after my original macro. As a bonus I got some really neat visualizations from it. I'm slowly getting better at iterative macros and coordinate problems like these!

 

Spoiler
Part 1: I used generate rows to create a mapping table of each cell & value to each adjacent cell & value. Then I used a mapping table that I created to determine which adjacent cells contained valid values along the loop. From there, I used an iterative macro to loop through each cell in the loop, and divided the length of the full loop by 2 to get the answer. I think there are more optimal ways to do this calculation, and I'd like to explore it when I'm fresh.

Part 2: Yay spatial tools! Created points for the points along the path, built a sequence polygon, and then used a spatial match to determine which points were within the polygon. I beat my head against a wall trying to figure out how to determine which points were bound by the loop within my iterative macro, until I remembered the amazing spatial tools available in Alteryx :) It took me a bit to figure out how to get my iterative macro to output the points in the correct sequence, but a very simple tweak fixed that for me (after lots of trial and error).

Workflow:

D10.png

Mapping table of valid path values: 
D10Mapping.png

Iterative Macro:

D10Macro.png

Spatial Visualization of my pipe loop:
D10 Loop Map.jpg
Visualization of the points bound within the pipe loop:
D10 Matches.jpg

 

DaisukeTsuchiya
13 - Pulsar

Day10 is so hard again.
It took 4.5 hours to create WF but process is completed in 2min for P1 and P2.

Spoiler
スクリーンショット 2023-12-10 185524.pngスクリーンショット 2023-12-10 185550.pngスクリーンショット 2023-12-10 184016.png
gawa
15 - Aurora
15 - Aurora

My Sunday comes to an end while solving this.

Spoiler
What's going on in this WF? I don't remember.
image.png
patrick_digan
17 - Castor
17 - Castor
Spoiler
I did normal x/y coordinates for part 1 but spatial for part 2.
image.png
AkimasaKajitani
17 - Castor
17 - Castor

Tough challenge.

 

Spoiler
I could not think of a way to do Part 2 other than to use the spatial tool.
The macro to search for routes was also completed after some twists and turns, but it took quite some time until it worked properly. And my workflow is also messy. 

AoC_2023_10_02.png

AoC_2023_10_04.png

AoC_2023_10_03.png

JeffF
Alteryx
Alteryx
Spoiler
A Spatial Solution. Part 1 ran in under 2 minutes and part 2 ran in under 1 second.

Solution
2023_AoC_Day10_JeffF.png

Part 1 macro
2023_AoC_Day10_JeffF_Part1_IterativeMacro.png

Part 2 map
2023_AoC_Day10_JeffF_PartTwoMap.png
gawa
15 - Aurora
15 - Aurora

Make Group tool is useful in case like D10P1. Here is how to create groups with Make Group tool without macro.

Spoiler
Overall WF
image.png
1) Create X-Y coordinates as usual
2) Create 'neighborhood' coordinate by two Generate Rows tool for X & Y respectively. For D10P1 case, they can have 2 neighborhoods.
image.png
3) Find the ID of neighborhood points, and create ID-ID mapping table
image.png
4) Count ID-ID combination, and if count=2 those ID-ID pair is deemed connected.
5) Go to Make Group tool, and you get grouping data like this
image.png

 

SuguruYoshinaga
8 - Asteroid

Very hard challenge.

Spoiler
WF
image.png
macro for Part 1
 

image.png

Macro for Part 2
image.png



 

Labels