General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2022 Day 15 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team
Discussion thread for day 15 of the Advent of Code - https://adventofcode.com/2022/day/15
8 REPLIES 8
clmc9601
13 - Pulsar
13 - Pulsar

This felt much easier than the last few days. Both parts can add an optimization challenge depending on your approach.

 

Spoiler
I had to redesign and optimize a few times. My workflow still took 11 minutes to run with AMP, mostly due to Make Group processing 65 million rows.

Screen Shot 2022-12-14 at 11.45.55 PM.png

AkimasaKajitani
16 - Nebula
16 - Nebula

In a last few days, I didn't hold the time to do the challenge because of my work and year-end party, but today I did it! Certainly, today's challenge is easier before a few days.

 

Spoiler
AkimasaKajitani_1-1671110737396.png

 

The easiest way to do this was, as expected, to explode the number of records, so I had to do it different way.
So,it took about 4 minutes in part 2.

 

mmontgomery
8 - Asteroid

P1 was straightforward. P2 required some ugly brute force.

 

Spoiler
P1: Did a reference point on y=10 to get the value
mmontgomery_0-1671124040315.png


P2: Generate the min/max for each path by row. Then do a calc to determine if y_min <=[row-1:y_max] THEN 1 for the 14 rows possible. Filtered where THEN =0 and plug magic row back into original logic to determine x,y coordinate then final logic

mmontgomery_1-1671124350822.png

 

 

 

DataNath
17 - Castor

Managed to catch up on Day 15! Part 2 was really fun to try and figure out/optimise after realising I couldn't scaffold a 4m*4m grid to check against. Following a couple of ideas that still lead to huge blowups and cancelling a couple of workflows after 15-20 minutes, I decided to try and use spatial for this which actually ended up running in 0.2 seconds! Entire flow for P1+P2 takes ~17s.

 

Spoiler
DataNath_0-1671363715416.png

 

DaisukeTsuchiya
13 - Pulsar

It was difficult to resolve the performance issue for Part2.

Spoiler
Day4's overlapping concept is utilized for Part2 without using Join or Append Tool.
Process took 12 mins for part2 and most of them are for multi-Row formula to process 31M records.

DaisukeTsuchiya_0-1671374285129.png

 

SeanAdams
17 - Castor
17 - Castor

So - took a completely different approach to part 1 vs. part 2.  

Very quickly realised (i.e. after running for an hour) that solving part 2 by using a brute-force array would not work.

 

Spoiler
Part 1:

Part 1 I took a very brute-force approach.
- For each sensor - find the manhattan distance
- Then create a diamond shape of points based on manhattan distance of blocked spots
- Then combine all these
... and filter for the focus row.


This is almost all done in the input parser:
SeanAdams_0-1672415536980.png

 

And then the outer call looks like this.

SeanAdams_1-1672415578121.png

 


Part 2:
I originally did part 2 in the same way - it worked for the example test but didn't scale to the full data.

SeanAdams_2-1672415637656.png

 

To make this scale - switched to Spatial since this is really an intersection of squares exercise.

SeanAdams_3-1672415871401.png

To explain this.

The top piece creates a combined polygon of the diamonds for the coverage for every sensor.
The bottom piece creates the bounding box.
Then you subtract the top from the bottom and that tells you what pieces remain.
Split them into polygons
- The example test had thin sliver-type polygons - so I did a bit more work to see if I could fit in a 1x1 beacon - but this wasn't needed on the final data.

Things to watch out for:
- Use X & Y as floating point long & lat
- Scale these values up / down to fit within the range of -2;2 (this allows you to use Alteryx spatial tools which only allow Earth coords and staying within the range of -2;2 reduces issues of curvature since spatial tools are not flat-plain geometry but geography (spherical earth).

Step 1: Overlapping sensor areas:

SeanAdams_4-1672416181233.png


Step 2: Merge into one poly:

SeanAdams_5-1672416204783.png



Subtract from Bounding Box:

SeanAdams_6-1672416231234.png

 

Final Resul (tiny box with the centroid in the middle)
SeanAdams_7-1672416280385.png

 



 

patrick_digan
17 - Castor
17 - Castor

My workflow is slow and had 2Billion+records, but it worked well enough.

Spoiler
patrick_digan_0-1672835215966.png

 

Pang_Hee_Choy
11 - Bolide

although get answer via spatial, but still want to find another method. take less than 10 seconds in total.

 

Spoiler
part 1:

remember to take negative... stuck for hours due to the negative...

identify whether square touch the y = 2000000,
then merge the range instead of generating every position.

and deduct the Beacon.

part2:
using the equation method. 
assume all the side is 4 equation

upper_upward = y = x + c + distance
lower_upward = y = x + c - distance

upper_downward = y = -x + c + distance
lower_downward = y = -x + c - distance

as only one position, the point must attached to 4 lines above. (2 lines in x and 2 lines in y)
hence there must have variance of 2 for each pair above.

get the average of the C (just -1 or +1 as they are 1 position above or bottom), that is the equation for x and y.

intersect the equation, we can get the point x and y
Pang_Hee_Choy_0-1672996408974.png


and multiple the required 4000000 + [y]




 

Labels