php - Optimalization task -


i have problem optimalization function generate document tax free.

i add order positions : name, price, weight , numbers (count).

like:

product = array(); product[0] = array('name'=>'product_a','price'=>32.00,'weight'=>5.23,'numbers'=>100); product[1] = array('name'=>'product_b','price'=>22.00,'weight'=>2.23,'numbers'=>140); product[2] = array('name'=>'product_c','price'=>12.10,'weight'=>3.03,'numbers'=>150); product[3] = array('name'=>'product_d','price'=>5.12,'weight'=>4.03,'numbers'=>10); product[4] = array('name'=>'product_e','price'=>52.22,'weight'=>5.13,'numbers'=>22); 

no positions have generate smallest document tax free. in 1 document can have sum weight max 50 , sum price 2000 (price 1 element. if have numbers 100 result 100*price).

so need implode position , generete new document smallest count. when use 10 element (all 100) have add 90 elements next documents.

could me this? kind of algorithm should use? can told me step step how that?

first divide prices respective weights.

then sort them in descending order.

choose biggest value , store respective values of price , weight in different variables.

the choose second biggest value , add respective price , weight variables declared in above point.

repeat step 4 until price >=2000 or weight >=50.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -