I have a question about the get_amount_inside() function that I haven’t seen answered in other discussions.
I initially built the function by doing floor division of the outer area by the inner area
def get_amount_inside(self, shape) return self.get_area() // shape.get_area()
But thinking about the problem in the head I realized that for some instances you would have to readjust the remaining 1x1 squares to accurately fit another rectangle and square. Despite this issue the function would return 2 instead of 1.
For Example a 5x5 square can only contain one 3x3 square but 25 // 9 would return 2 instead of 1.
The prompt does not clarify this but does state No Rotations. So does this mean that my original function does not suffice in correctly returning the expected value in every instance? If so, would the code below work?
def get_amount_inside(self,shape): fieldWidth = self.width fieldHeight = self.height sectWidth = shape.width sectHeight = shape.height count = 0 while fieldWidth >= sectWidth and fieldHeight >= sectHeight: fieldWidth -= sectWidth fieldHeight -= sectHeight count += 1 return count
EDIT: The solution I made is below.
P.S. the only reason I made this post is because there are solutions being circulated on Polygon Forum that state the wrong answer (The first one I posted). I was just trying to shine light on an issue I found so that other people can maybe try to solve the problem correctly.
def get_amount_inside(self,shape): fieldWidth = self.width fieldHeight = self.height sectWidth = shape.width sectHeight = shape.height countWidth = 0 countHeight = 0 if fieldHeight > sectHeight: countHeight = fieldHeight // sectHeight if fieldWidth > sectWidth: countWidth = fieldWidth // sectWidth return countWidth * countHeight