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.
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:
So the math is done in the first line of the
find_largest_squarefunction:When we run this program it prints: