# Google Foobar challenge: Rabbit Test Subjects

The diabolical Professor Boolean has captured you and a group of your hapless rabbit kin as test subjects for his terrible experiments! You're not sure what his real plans are, but currently it seems he's trying to make everyone faster and smarter? He's exposing rabbit test subjects to novel chemicals, genetic manipulations, and pathogens; then measuring their completion time for various puzzles and exercises. Then again, there's a rumor he's developing a kind of zombie rabbit. You don't want to become a zombit!

Unfortunately, due to insubordination, and laziness, Professor Boolean just "eliminated" the lab assistant tracking all data from this research. Now, he's forcing you to sort through the notes and find something useful from the chaos. You have no choice but to abide by your captors evil rules. For now.

Of the subjects that have survived, each has a distinct file, with anywhere from 1 to 100 measurements of completion time for the tests. The measurements from the before and after cases are listed separately, but the ordering has been mixed up. You have to figure out the degree of improvement (0% to 99%, rounded to the nearest whole number) based on the two lists of results.

For example, if the first list of times is [22.2, 46, 100.8] and the second list is [23, 11.1, 50.4] you would return 50, because the times got 50% shorter: the 22.2 entry improved to 11.1, the 46 improved to 23, and the 100.8 improved to 50.4. Even though the data points are in different order, each improves by the same amount.

Write a function answer(x, y) which takes two lists of floating point performance scores and returns the improvement percentage, rounded to the nearest integer.

Test cases:

Inputs:

(double list) y = [1.0]
(double list) x = [1.0]


Output:

(int) 0


Inputs:

(double list) y = [2.2999999999999998, 15.0, 102.40000000000001, 3486.8000000000002]
(double list) x = [23.0, 150.0, 1024.0, 34868.0]


Output:

(int) 90


The test cases are successful, but for some reason when I try to verify my answer, it says: There was a problem evaluating your code.

Is there a better way to solve this?

def answer(y,x):
totalTime1 = 0
totalTime2 = 0
for time in x:
totalTime1 += time
for time in y:
totalTime2 += time
improvement = (1-(totalTime1 / totalTime2)) * 100
return int(improvement)

• Welcome to Code Review! Does your code work as expected? While it does pass the test cases, you do say how the service rejects your code. – SirPython Mar 28 '16 at 23:38

For one thing, the assignment was to define a function answer(x, y), not answer(y, x). You could also put the built-in function sum() to use. I believe the key point is rounded to the nearest whole number. int() always goes down. That is 4.9 results in 4, but rounding would result in 5. You can use the built-in function round(). In Python3 it returns an integer, but in Python2 it returns a float. To take care of both cases, convert the rounded version to an int:
def answer(x, y):