Skip to content

Instantly share code, notes, and snippets.

@somic
Created December 14, 2010 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somic/739949 to your computer and use it in GitHub Desktop.
Save somic/739949 to your computer and use it in GitHub Desktop.
def revenue_maximizing_spot_price(n, bids):
assert len(bids) <= n, "does not work when the number of bids exceeds n"
revenue, spot_price = max(
[ (sum([p for x in bids if x >= p]), p) for p in bids ])
return spot_price, revenue
if __name__ == '__main__':
print revenue_maximizing_spot_price(10, [ 1, 2, 5, 50 ])
# -> (50, 50)
print revenue_maximizing_spot_price(10, [ 1, 2, 5, 45, 50 ])
# -> (45, 90)
print revenue_maximizing_spot_price(10, [ 1, 2, 25, 45, 50 ])
# -> (45, 90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment