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
https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/
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.

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;}?>

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.