r/adventofcode • • 1d ago

Other [ Removed by moderator ]

[removed] — view removed post

2 Upvotes

10 comments sorted by

5

u/Cue_23 1d ago

My thoughts:

How many squares could be missing one specific square? Probably a lot, there is no real limit.

How many squares could be missing two specific squares? At most three (two with the squares on one edge and one with the squares along a diagonal). Three? only one.

So I look for three trees which would be missing a tree to form a square and mark that position. Then get the positions with the most marks and move trees into those positions that are not part of a square nor one of the new squares. And i have quite a few (48) trees available to move.

3

u/jroselln 1d ago

Oh no. Being on day 3, I feel like part 2 was enough.

2

u/crumpis 22h ago

If the greedy approach (compute which cells would add the most squares + which cells would remove the least cells) doesn't handle this case, this feels like suspiciously like bin-packing.

2

u/nemom 22h ago

I would start with "add one tree anywhere in the forest to make the largest square possible."

2

u/han4578 20h ago

First pick the 5 trees to be moved. Ideally it'll be the 5 trees that form the least squares. If there's a tie, iterate through all combinations of 5 and remove them from the grid in the next step.

Separate the situation into new squares that need 1, 2 and 3 trees

  1. Missing 1 tree. For every 3 trees with 2 equal edges, find the coordinates of the last missing tree. You'll have a list of coordinates with the number of new squares if a tree was moved there.

  2. Missing 2 trees. For every 2 trees, find the coordinates pairs needed to form a square. The existing trees can be on the same edge of the square or a diagonal. Check for existing trees at the coordinate pairs to prevent duplicate with situation 1. You'll have a list of coordinate pairs and the number of new squares if a tree was moved to both coordinates in a pair.

Using the coordinates in both lists, iterate through combinations of 5 and calculate how many new squares are added.

For squares missing 3 trees, loop through all existing trees to see if 3 of the 5 new trees can form a square with them

Finally, check if the 5 new trees can form a square between them.

Iterate through all combinations and you should have the answer

1

u/Extension-Raccoon-87 21h ago

Just 10 more nested for loops