Beazley's Problem

Liste des GroupesRevenir à cl python 
Sujet : Beazley's Problem
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.python
Date : 21. Sep 2024, 14:15:37
Autres entêtes
Organisation : Stefan Ram
Message-ID : <problem-20240921130726@ram.dialup.fu-berlin.de>
  I recently caught this vid "The Problem with The Problem"
  featuring David Beazley. In it, he dropped this problem
  that went something like:

|Picture this: there's a guy who owns a movie theater in Santa Monica,
|and he's got the freedom to set ticket prices however he wants.
|
|But here's the catch: the higher he sets the price, the fewer
|people show up. So, he recently did a little experiment to
|figure out exactly how ticket prices affect attendance.
|
|Turns out, when he charges $5.00 per ticket, about 120 folks
|come to watch a movie. (=1)
|
|But if he knocks the price down by just 10 cents, an extra 15
|people show up. (=2)
|
|Now, here's where it gets tricky. More people means more
|costs. Running each show sets him back $180, and every person
|who walks through the door adds another four cents to his
|expenses. (=3)
|
|What he's trying to figure out is how all these numbers play
|together so he can set the perfect ticket price that brings in
|the most cash.

  David basically said, "The owner wants to find out how to maximize
  his profit."

  He didn't spell out the exact task, but mentioned he throws
  this curveball in some of his courses. And I'm betting my
  bottom dollar they're Python programming classes!

  So I hit pause on the video and thought to myself: "How would I
  tackle coding this bad boy?"

  Before you keep reading, why don't you take a crack at it yourself?

  Alright, so here's how I approached it: We know that when the
  price x is 5 bucks, the number of people n is 120 (^1).

n( 5 )= 120

  We know that for every i times 0.1 dollar price hike, (-i)*15 more
  people n show up (^2).

n( x + 0.1*i )= n( x )- 15*i

  The overhead c for an event is 180 smackers plus 0.04 bucks per
  head (^3).

c = 180 + n*0.04

  So the profit p for an event with n people, each shelling out
  x dollars, comes out to turnover minus costs:

p( x )= n( x )*x - c.

  A change in attendance that's exactly proportional to the
  price means the number of people depends on the price in an
  affine-linear way. By plugging in the two known relationships
  "n( 5 )= 120" and "n( x + 0.1*i )= n( x )- 15*i", we can
  nail down the coefficients of the affine-linear function:

n( x )= 870 - 150*x.

  The profit "n( x )*x - c" then becomes

p( x )= n( x )*x - c
      = -150*x*x +( 870 + 150*0.04 )x - 180 - 870*0.04.
 
  The derivative of the profit with respect to price x is
 
p'( x )= -2*150*x +( 870 + 150*0.04 ).

  By setting the derivative to zero, you find the maximum at

x = 87/30 + 0.02

  if my math isn't off the rails!

  So, my approach to this programming challenge would be to
  say that it's best to determine the maximum analytically,
  and then the Python program boils down to:

print( "The maximum profit is at" )
print( 87/30 + 0.02 )
print( "viewers." )

  Or you could install one of those fancy symbolic math libraries
  for Python and let it handle all the manual transformations
  I just walked through.

  Now I'm on pins and needles to see where David Beazley's talk
  goes from here!



Date Sujet#  Auteur
21 Sep 24 * Beazley's Problem14Stefan Ram
21 Sep 24 `* Re: Beazley's Problem13Paul Rubin
21 Sep 24  `* Re: Beazley's Problem12Stefan Ram
21 Sep 24   `* Re: Beazley's Problem11Paul Rubin
23 Sep 24    `* Re: Beazley's Problem10Annada Behera
23 Sep 24     +* Re: Beazley's Problem8Stefan Ram
24 Sep 24     i+- Re: Beazley's Problem (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
24 Sep 24     i+* Re: Beazley's Problem4Paul Rubin
24 Sep 24     ii+- Re: Beazley's Problem1Annada Behera
10 Nov22:48     ii`* Re: Beazley's Problem2david k. combs
10 Nov23:55     ii `- Re: Beazley's Problem1Paul Rubin
26 Sep 24     i`* Modern Optimization (was: Beazley's Problem)2Stefan Ram
26 Sep 24     i `- Re: Modern Optimization1Stefan Ram
6 Oct 24     `- Re: Beazley's Problem1Antoon Pardon

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal