find the largest square foot given an area

343 Views Asked by At

Given an area of n square foot, I need to be able to find the largest square foot I could make in the given area.

Example: if I had a total area of 12 square foot, I would be able to make one 3x3 square (with a total area of 9), and that would leave 3 square foot. 12 = [9, 1, 1, 1]

How do I solve this? or If you could just point me in the right direction that would be cool too. I just don't know what to google honestly.

the Euclidean algorithm seems to be the answer but that requires two input, now I am thinking maybe I can get the area's square root?

Now, I little background about this problem. I just started learning python programming and I was practicing on a website called "https://www.codewars.com", so yeah I am stuck on this "Kata". yes, I can skip it but I actually want to know how to solve this. please help.

2

There are 2 best solutions below

0
On BEST ANSWER

As commented by MalayTheDynamo, you should use the floor of the square root of the area. Here is a simple python program that explains how to code this:

import math

def find_largest_square(area):
    max_side = math.floor(math.sqrt(area))
    print "area:", area, "=>", max_side, "x", max_side

find_largest_square(12)
find_largest_square(17)

So the math is done in the first line of the find_largest_square function:

max_side = math.floor(math.sqrt(area))

When we run this program it prints:

area: 12 => 3.0 x 3.0
area: 17 => 4.0 x 4.0
0
On

Suppose given area is A

now let's find the side of the square x*x=A

thus $x=\sqrt(A)$ because side is always positive

but you are looking for an integer

thus take the floor

your answer is the floor of $(\sqrt A)$