Polygon Area Calculator: Fitting Rectangles ? Spec Clarification required

Re: Clarification sought for specification of the Polygon Area Calculator.

Question: What method is required to solve how many rectangles will “fit” ?

The spec requires to know how many times (say) rectangle2 will
fit into rectangle1 . Rotation not permitted. (See end for full text of spec).

Folks seem to be solving this with (essentially):
Fits = rectangle1_Area / rectangle2_Area

But I don’t see how that works.
Say rectangle1 has area 100 square units and rectangle2 has area 25 square units.
Fits = 100 / 25 = 4 right ?
But what if rectangle1 is 1100 and rectangle2 = 55. Then fit = 0.
I know how to solve this problem but do I have to ?
It’s not simple and I’d like to know what the testers require.
Many thanks.

Here is the relevant part of the spec:

  • get_amount_inside: Takes another shape (square or rectangle) as an argument. Returns the number of times the passed in shape could fit inside the shape (with no rotations). For instance, a rectangle with a width of 4 and a height of 8 could fit in two squares with sides of 4.

It shouldn’t be a ratio of areas. You need to compute how many small shapes fit inside the big one side to side and then again top to bottom.

1 Like

I agree.
Thank you for your opinion.

compare areas would suggest rotations are permitted. I dont think the tests would permit such solution(or do they?).

A working solution to meet the requirement can actually appear pretty simple(once you put it on paper/code). Here is the logic i used:

I compared how many times width of rect A would fit in the width of rect B, then i compared how many times the height of rect A would fit in height of rect B. You can use “//” operator to negate decimal values. Then i multiply the two values.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.