I got p2 to run in 13s, but I'm sure that's not where I'll end up. For any x,y, I calculate a subgrid size starting where n =1. Then I recurse, calling for x,y,n+1, and passing the total we just created. That way I'm not looping through too much data redundantly. I just add the sides to the new larger square that weren't calculated in the last step.