Skip to content

Instantly share code, notes, and snippets.

@theneosloth
Created June 22, 2016 01:57
Show Gist options
  • Save theneosloth/cfa61ca39e8cfaff4665573d0fd2ca2d to your computer and use it in GitHub Desktop.
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
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