Advent of Code 2024 Day 12 (BaseA Style)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Discussion thread for day 12 of the Advent of Code - https://adventofcode.com/2024/day/12
- Labels:
- Advent of Code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
take me awhile to remember how to use "Make Group" tool. save time from build manualy.
thanks for past events got similar questions.
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
another tip:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I applied spatial analysis to both part 1 & 2. It was hard to solve for me.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Very cool problem with application in (ML) Image Processing for edge detection.
V2 (no macro; thanks to the very powerful Make Group Tool + a lot of simplification throughout the workflow):
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I did not use macros. For P2, I struggled by drawing diagrams in Excel.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.👍
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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)
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Solved!
I remembered too late that polygons basically hold their points in a clockwise order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Fun use case for spatial tools today 😀
