Created
October 6, 2022 18:36
-
-
Save davipatti/f6e98d310ec848c4206231553a35c31b to your computer and use it in GitHub Desktop.
Cinema problem, https://www.youtube.com/watch?v=t-IUY6QrJyU
This file contains hidden or 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
#!usr/bin/env python3 | |
def attendance(price: int): | |
"""Number of people that will attend for a given price.""" | |
formula = 120 - ((price - 5) / 0.1) * 15 | |
return max((formula, 0)) | |
def cost_of_performance(n_people: int) -> float: | |
"""Cost in dollars of performance.""" | |
return 180 + 0.04 * n_people | |
def ticket_sales_of_performance(n_people: int, price: float) -> float: | |
"""How much does the performance make?""" | |
return price * n_people | |
def profit(price: float) -> float: | |
"""The amount of profit to expect given a certain price.""" | |
n_people = attendance(price) | |
return ticket_sales_of_performance(n_people, price) - cost_of_performance(n_people) | |
prices = [x / 10 for x in range(100)] | |
print(max(prices, key=profit)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment