Created
December 14, 2010 03:01
-
-
Save somic/739949 to your computer and use it in GitHub Desktop.
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 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