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
DataNath
17 - Castor

Finally caught up on day 10! Really enjoy the challenge of these grid problems and thinking how best to tackle them whilst limited to table structures in Alteryx. Part 1 and 2 macros are very similar - I just added an extra print output of the co-ordinates of each iteration so that I could build a polygon and conduct spatial matching for P2.

 

Spoiler
Day10WF.png

Day10.1Iterative.png

Day10.2Iterative.png
mmontgomery
11 - Bolide

Good lord this took me a while

Spoiler
Once I got the hint to solve p2 spatially (h/t @kelsey_kincaid), I built two separate polygons based on my two paths. After that I combined the objects and compared them to my '.' data points.

My P1 approach was to define the pieces as 'match' or no match based on the prior step, current step, and next step (long formula below). Also, I created a yxdb to read from/write to with updated path info to ensure the same coordinate wasn't used twice. So I populated the .yxdb first, then disabled the container and ran the macro
Day10P2_Workflow.pngDay10P1_Macro.pngDay10P1_Workflow.png

 

Carolyn
9 - Comet

FINALLY got Day 10 done. I was busy on Sunday and missed this and finally had a chance to get it done. 

 

I appreciate @kelsey_kincaid posting their solution. I got to the Spatial Match on Part 2 and wasn't sure what to do with the output :D 

 

Spoiler
Part 1.pngPart 1 Macro.png

  

Part 2.png

 

 

alisonpitt
11 - Bolide

I knew I would get to use spatial tools sooner or later! I feel like this is one where Alteryx definitely makes part 2 easier. NOT that it was easy 😅

Spoiler
Part 1 - since we know it's a closed loop, traverse paths until you hit a coordinate you've hit before, sum up the steps on the intersecting paths and divide by 2. Ish.
10-1-ap.png10-1-macro-ap.png

Part 2 - this time I retained the whole path in a big old string with the sequence of directions...and stuck the two paths end to end (reversing the second one to create a full loop). Then I used spatial tools to find all the points inside the polygon but not on the border, and counted them up.
10-2-ap.png10-2-macro-ap.png

Update - I just HAD to render the final map because it felt like such an achievement when I finally got there!
10-map-output.jpg
Pang_Hee_Choy
12 - Quasar

think of spatial for part2 but no luck, thanks @kelsey_kincaid 

 

Spoiler
part1: 
no idea why it run for 2~ minutes. 

part2:
go for spatial to get right answer
and after that I search in YouTube got one comment is said
just x2 the map, free up the space and use fill-up the tank method.

built for both methods.
Watermark
12 - Quasar
12 - Quasar

D10P2 - 

 

This hot rod runs in a smokin  0.8 sec!!

 

Spoiler
AOC 2023 Day 10P2.jpg

DaisukeTsuchiya
13 - Pulsar

I post again with solution in yxzp.

 

Spoiler
スクリーンショット 2023-12-15 181133.pngスクリーンショット 2023-12-10 185550.pngスクリーンショット 2023-12-10 184016.png
SeanAdams
17 - Castor
17 - Castor

Tunnel problems – really allows you to dig into them  <wah wah wah>

Part 1 was pretty brute force – and ran in 6:28

Part 2 I gave up on computational approaches (I need to go an look at other people’s solutions) and used spatial – worked like a charm. 

😊 oh, and got to use control containers here too!

 

Details in the spoiler below.

 

Spoiler

Part 1:

 

SeanAdams_0-1702991048984.png

 

 

Really just 2 steps:

  • First prep the data – just break this into rows and columns
  • Then go into an iterative macro that generates all combinations of moves from that starting position.
  • Before we go into this – we set the starting position and mark this as current (i.e. being processe)

 

Find paths macro:

The way this works is that from each current point, you look at where you can move to – if there are no possible moves then exit

The explosion to possible moves happens in the join and in the formula immediately after it

SeanAdams_1-1702991048999.png

 

 

The output of this is a list of all the tunnel pieces (from X to Y) and an engine iteration number.   The highest engine iteration number is also the furthest point from the start since it took us the most steps to get there – so the problem is solved.



Part 2:

So – we’re coming into Part 2 with all the tunnel pieces – however I couldn’t figure out a pretty way to computationally see if something was inside or outside the tunnel.   I did start by working from the outside edges inwards, but that doesn’t work for the stuff where the rabbit squeezes between the tunnel pieces.

 

Enter Spatial.

 

Here’s the recipe:

  • Take each of the vertices (tunnel pieces) and convert them into a Spatial Line
  • SeanAdams_2-1702991087658.png

     

  • Then take all of the lines, and convert them into a single polygon

 

SeanAdams_3-1702991087660.png

 

 

  • Then create a dot for each non-tunnel point (row / col)
  • SeanAdams_4-1702991087665.png

     

  • Then all you need to do is use the spatial formula ST_Within([Centroid],[newPoly]) to see if the point is inside the poly or not – job done!
SeanAdams_5-1702991087685.png

 

 

And why the control container – ‘cause you only want part2 to run when the output from Part 1 completes and the output file finishes writing

SeanAdams
17 - Castor
17 - Castor

thank you for writing this up @AndrewDMerrill - very generous of you to spend the time - and your explanation makes complete sense.

 

I feel like I cheated a little and used the spatial tools for part 2 - but it is BaseA :-)

SeanAdams
17 - Castor
17 - Castor

great writeup and unique solution - thank you for taking the time @gawa 

Labels