A little fun: Solar Doomsday

Once in a blue moon, when you have just looked up something about Python using Google, some kind of fun Python challenge will pop up. It’s happened to me twice. Both times there has been some warning that if I exited the program I would not be able to return. The first time it was some simple program construction wrinkle that I had just used in one of my first programs. I got so excited that I exited the program. Oh well.

The second time it popped up just as I was leaving to meet my wife for lunch. I didn’t have time to read the whole scenario, which I think was called Solar Doomsday, but this time I knew enough to just leave the computer up and running and not touch anything. When I returned from lunch I took a nap and after that I remembered I had left the computer on. Everything was still as I had left it. It was a funny, simple little challenge that took about ten minutes to program. I’ll describe the scenario in a minute so you can see for yourself if you can solve it.
First, however, be advised that you will need to be comfortable in a Linux environment to even get started. Bringing up guest help gets you:

foobar:~/ guest$ help
Use the following shell commands:
cd change directory [dir_name]
cat print file [file name]
deleteme delete all of your data associated with foobar
edit open file in editor [file_name]
ls list directory contents [dir_name}
request request new challenge
status print progress
submit submit final soltion file for assessment [file_name]
verify runs tests on solution file [file_name]

From what I remember there were multiple challenges after the one I will call Solar Doomsday. I never got to see them – I’m not sure why. Before uploading my solution I ran it both on my Windows 10 machine and on a Raspberry Pi. It worked perfectly in both environments; but when I uploaded it to the big foobar at Google (their name, not mine) it would not verify. Well, they did call the whole thing “foobar” and I guess they knew their own product well. Here is the challenge to the best of my memory:

The Solar Doomsday Challenge:
Commander Lambda wants to destroy some planet full of rabbits but to do so, he/she must have some extra power that will be generated by soloar panels made from one very large piece of material. For some reason, every solar panel must be exactly square and can only be cut to even 1 square yard increments. The larger the panel, the more efficient it works so we only want the best solution.

You work for Lambda and are charged with developing a program that will generate a list of panels by size that can be made from any given sized piece of the solar material measured in an even number of square yards. By even, I mean no decimal places. So to recap, input square yards of material; output a list of panels by decreasing size in square yards.

I don’t think they are anal enough to expect error checking on input so I would skip that. Below you will find my solution – it is A solution, not THE solution. See if you can do better.

#solar_doomsday
#John Oakey
import math #will need a square root function and Python doesn't have one in core commands
intlist=[]  # will need some place to store the pannel sizes, a list of integers
x="True"  # a boolean variable
#now here is our function
def nextsquare(material):
    tempmaterial=float(material) #need a floating point variable to use taking square root
    panelsize = int(math.sqrt(tempmaterial))
    return panelsize # the biggest piece we can make is squareroot of what is available

material = input("How many square yard of material?: ")
print("your input: ", material) # record the input
while x=="True":
    panelsize=nextsquare(material)
    intlist.append(int(panelsize*panelsize))
    material=int(material)-int(panelsize*panelsize)
    if material<1:
        x="False"
        break
print("Panels we can produce by size in square yards: ", intlist)
print("Death to the Bunnies!")