Created
June 22, 2016 01:57
-
-
Save theneosloth/cfa61ca39e8cfaff4665573d0fd2ca2d to your computer and use it in GitHub Desktop.
Returns a percentage difference between two sets of values. Used as a solution for the level 1 google foobar problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def answer(y, x): | |
# Make sure we are always comparing the smaller list to the larger list. | |
if (sum(x) > sum(y)): | |
y,x = x,y | |
# The quotient of each one of the matching elements in an array | |
result = [b/a if a else 0 for a,b in zip(sorted(y), sorted(x))] | |
# Average percentage of increase, rounded up to one. | |
return int(100 - (sum(result) / float(len(result))) * 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment