Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2024 Day 12 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team

Discussion thread for day 12 of the Advent of Code - https://adventofcode.com/2024/day/12

19 REPLIES 19
PangHC
12 - Quasar

take me awhile to remember how to use "Make Group" tool. save time from build manualy.

thanks for past events got similar questions.

 

Spoiler
part1:
1. get adjacent cells, if neighbour not same, then it counted as perimeter.
2. get the region id.
3. join and make the group by and calculation etc

part2:
scan for side by side, use multiple rows to identify the sideID

eg:

xxx<--1
xx<--2
xxx<--3
xxx<--3

if [row-1:y] = y and [row-1:x] = [x]-1 then [sideID] else [sideID] + 1 endif
Screenshot 2024-12-12 151657.png
another tip: 
Spoiler
remember to check the sorting, i.e. check for engine compatibility mode for AMP.

 

gawa
16 - Nebula
16 - Nebula

I applied spatial analysis to both part 1 & 2. It was hard to solve for me.

Spoiler
Part1:
1) Define 1 x 1 square for all tiles, and create regions + outer frame object(surrounding the entire map).
2) Buffering each regions a bit and matching each other will create perimeter objects. Calc their length and area of regions by Spatial Info tool. *Length will be double of the length, so divided by 2.
3) Cal unit area and length of 1 x 1 square separately, and divide the result of 2) by these unit values.

Part2:
Using Multi Row Formula, count how many perimeters exist for each region. To be honest, the logic I applied was finalized through try and error, and it contains fuzzy logics.

image.png
CoG
14 - Magnetar

Very cool problem with application in (ML) Image Processing for edge detection.

 

Spoiler
Part 2 can be solved by understanding that if you shift all cells in each of the cardinal directions, then remove all cells that overlap within the same group, all you are left with is a side/edge. Count all such sides, and multiply by the number of plots in a group (area) and sum to achieve the answer:

Main.pngGroup Plots.png

V2 (no macro; thanks to the very powerful Make Group Tool + a lot of simplification throughout the workflow):

Spoiler
Main V2.png

 

DaisukeTsuchiya
14 - Magnetar

I did not use macros. For P2, I struggled by drawing diagrams in Excel.

 

Spoiler

For P1, I grouped adjacent elements using the "Make Group" Tool. A single plant would have fences on all four sides, but if it is adjacent to others, the shared sides are subtracted in the calculation.

For P2, I took the approach that irregularities (convexities or concavities) add more edges, and I calculated the edges by dividing the analysis into vertical and horizontal directions.

Spoiler
スクリーンショット 2024-12-12 211032.pngスクリーンショット 2024-12-12 205625.png
Yoshiro_Fujimori
15 - Aurora

I got stuck with Part 2 and got a hint from @gawa that Spatial Tools works, and it actually worked. Thanks gawa-san!

Spatial Tools are very powerful in "visualizing" the process.👍

 

 

Spoiler
Part1
Used Make Group Tool to find the areas and counted the neighbors of each plant.

Part2
Create squares for each plant and combine them with the area ID.
Split it to Regions with Poly-Split, Convert it to boundary with Formula, 
Split each to Points, and then count the corners referring to the coordinates with Multi-Row Formula.
Day12_workflow.png

 

 

mark-spain
8 - Asteroid

I hadn't come across the Make Group tool before but it did exactly what I needed for this challenge when I was struggling to identify the area and perimeter of distinct groups. I didn't use any macros as I was able to find and check the values of adjacent cells using Generate Rows. I did find Part 2 very tricky and was originally considering a convoluted method to try and count the number of corners (because corners = edges), but couldn't wrap my head around the best way to do that. In the end... (see spoiler)

Spoiler
For Part 1, I considered the adjacent cells that matched the current cell, which allowed me to create groups using the Make Group tool. 

For Part 2, however, I considered the adjacent cells that did not match the current cell, which, with a few headaches figuring out the correct sort order and formulae, enabled me to check if the previous unmatched cell was part of the same edge or part of another edge - based on row/column sorting. By finding the greatest count of edges per direction and then aggregating that figure on a Group level I could join to the Area data calculated in Part 1 and calculate the discounted price.

AoC 2024 Day 12.png

 

AkimasaKajitani
17 - Castor
17 - Castor

Solved!

 

 

Spoiler
I got to the Make Group tool in Part 1 early on, but took a long detour in Part 2. When I first tried Spatial tools in part2, I was disappointed by the extra points that were left over. I then tried to use an Iterative macro to identify the edge, but it didn't solve some particular patterns. I ended up using spatial tools to identify the order of the perimeter points, and then eliminated the straight line ones. I used some of the logic from the detour, so maybe it wasn't a waste in the end. I solved it just before going to bed somehow.
I remembered too late that polygons basically hold their points in a clockwise order.

 AoC_2024_12_02.png

AoC_2024_12_03.png




 

 

leozhang2work
10 - Fireball
Spoiler
day 12 - 1.pngday 12.png

Taking hint from @gawa's spatial approach, part 1 become very easy

Hub119
11 - Bolide
11 - Bolide

Fun use case for spatial tools today 😀

Spoiler
AoC D12 Pic.png
Labels
Top Solution Authors