stuck on Google python challenge
im working on a challenge that requires a function(input) and outputs a list of outcomes. Adult with some kind of math aut
Directions
All of the solar panels must be squares. Fortunately, you have one very large and flat area of solar material and you can piece together any excess panel material into more squares. For example, if you had a total area of 12 square yards of solar material, you would be able to make one 3x3 square panel (with a total area of 9). That would leave 3 square yards, so you can turn those into three 1x1 square solar panels.
Write a function solution(area) that takes as its input a single unit of measure representing the total area of solar panels you have (between 1 and 1000000 inclusive) and returns a list of the areas of the largest squares you could make out of those panels, starting with the largest squares first. So, following the example above, solution(12) would return [9, 1, 1, 1].
My Logic
Why cant the squares be all of the numbers instead of being cut up ? the example was 12 square areas why cant that be a ssingle big quare ?...... seems arbitrary
what ive come up with is something either with dividing the input number or using the `%` and doing something with the remaining numbers or import math and use math.sqrt
import math
def myfunc(x):
mylist = []
fnum = x / (9 ?)
rnum = x % (idk)
for i in fnum, rnum:
mylist.append(i)
return mylist
UPDATE:
This is what i came up with. thank you for the feedback
def solution(area):
tnum = area
mylist = []
while tnum > 0:
mylist.append(int(math.sqrt(tnum))**2)
tnum = tnum - int(math.sqrt(tnum))**2
return mylist
this is what I came up with. thank you for the feedback and code examples.
8 comments · 100% upvoted · other discussions
Because 12 squares can't make a square. 9 or 16 can. That's a clue for your logic.