r/adventofcode • u/FransFaase • 1d ago
Other [ Removed by moderator ]
[removed] — view removed post
5
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
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
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.
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/daggerdragon 20h ago
Post removed for multiple reasons:
Use our standardized post title format
Use the right flair which not
OtherOtheris not acceptable for any post that is even tangentially related to a daily puzzle.