Calling all Racers for the Alteryx Grand Prix! It's time to rev your engines and race to the stage at Inspire! Sign up here.
alteryx Community

# General Discussions

Discuss any topics that are not product-specific here.

## Advent of Code 2022 Day 15 (BaseA Style)

Alteryx Community Team
8 REPLIES 8
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.

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

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.

8 - Asteroid

P1 was straightforward. P2 required some ugly brute force.

Spoiler
P1: Did a reference point on y=10 to get the value

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

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

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.

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:

And then the outer call looks like this.

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.

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

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:

Step 2: Merge into one poly:

Subtract from Bounding Box:

Final Resul (tiny box with the centroid in the middle)

17 - Castor

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

Spoiler

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

and multiple the required 4000000 + [y]

Labels