Part 2 got me pretty confused. I admit I resorted to asking Claude for algorithmic hints, though explicitly told it not to give me direct answers or code. I was on the right track, but off by one errors will ruin your day.
For this one I take all pairs of trees (P,Q) and try to trace a complete square using the vector between P and Q.
Q - P gives you the vector that moves along one side of the square from P to Q. If you rotate that vector 90 degrees and add it to Q, you should end up at another corner on the square. If you repeat this process 4 times and land on a tree every time, you have a complete square.
1 Like
Today I just went dirty, brute forcing with a O(n^3) for part 1 and O(n^4) for part 2. Going through all the possibilities and seeing if that is a valid square. I had to make sure no duplicates were considered.
1 Like