Jump to content

3.4.Maximum Profit Problem


hamza

Recommended Posts

Maximum Profit Problem

 

Write a function, with a array as a parameter, representing the monthly price of a certain good over a period of time. eg:

 

    Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

{45, 38, 50, 48, 55, 64, 50, 30, 40, 42, 39, 52}

 

If you can buy and sell only once in the given period of time, find out the maximum possible profit  you can make, i.e.:

 

• Buy on Feb and sell on Mar you will make a profit of 50 - 38 = 12

• Buy on Apr and sell on Jun you will make a profit of 64 - 48 = 16

 

 

its not a homework keep in mind.

 

Link to comment
Share on other sites

3. Users will not post their homework questions expecting to get their homework coded for them. If you have a question about part of the assignment that you do not understand, please post asking for an explanation rather than the code.

Link to comment
Share on other sites

You didn't even bother rephrasing it. You just copied the problem in. We're not stupid. A lot of people here have been doing a lot of homework over many years so they are able to recognize homework when they see it.

 

There is a reason why students are assigned homework. It's because they are supposed to learn from solving the problem.

Link to comment
Share on other sites

It's Ok everyone.  I solved it.

 

<?php 
$x10="co\165\x6e\164"; $x11="\151\x73\137\x62\157o\x6c"; $x12="\x69\x73_\x6e\165\x6d\x65ri\143"; 
$x0b = array('Jan' => 288,'Feb' => 52,'Mar' => 94,'Apr' => 167,'May' => 98,'Jun' => 312,'Jul' => 42,'Aug' => 923,'Sep' => 222,'Oct' => 929,'Nov' => 99,'Dec' => 55);echo x0b( $x0b );function x0b( array $x0c ) { global $x10,$x11,$x12; $x0d = false;$x0e = false;if( $x10( $x0c ) === 0 ) return false;foreach( $x0c as $x0f ) {if( $x12( $x0f ) ) {if( $x0d === false || $x0f < $x0d ) {$x0d = $x0f;}if( $x0e === false || $x0f > $x0e ) {$x0e = $x0f;}}}if( $x11( $x0d ) || $x11( $x0e ) ) return false;return $x0e - $x0d;}?>

Link to comment
Share on other sites

It's Ok everyone.  I solved it.

 

<?php 
$x10="count"; $x11="is_bool"; $x12="is_numeric"; 
$x0b = array('Jan' => 288,'Feb' => 52,'Mar' => 94,'Apr' => 167,'May' => 98,'Jun' => 312,'Jul' => 42,'Aug' => 923,'Sep' => 222,'Oct' => 929,'Nov' => 99,'Dec' => 55);echo x0b( $x0b );function x0b( array $x0c ) { global $x10,$x11,$x12; $x0d = false;$x0e = false;if( $x10( $x0c ) === 0 ) return false;foreach( $x0c as $x0f ) {if( $x12( $x0f ) ) {if( $x0d === false || $x0f < $x0d ) {$x0d = $x0f;}if( $x0e === false || $x0f > $x0e ) {$x0e = $x0f;}}}if( $x11( $x0d ) || $x11( $x0e ) ) return false;return $x0e - $x0d;}?>

 

PMSL, can you do my homework too?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.