If It is possible then show me...It's a challange | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

If It is possible then show me...It's a challange

11 Items are in a shop and every item has a different price and weight. a thief is going to stolen items but it has capacity of 79 units of weight to carry. now he has to carry more expensive items in 79 units. how can we make an algorithm for that problem? weight & price 6 6 28 28 41 40 32 31 38 36 10 9 29 26 26 23 66 57 21 18 2 1

27th Feb 2018, 1:48 PM
Muhammad Naeem Jamali
Muhammad Naeem Jamali - avatar
5 Answers
+ 2
Sort based on a ratio of price to weight. ie. return (a.price/a.weight>b.price/b.weight?a:b); or something functionally equivalent.
27th Feb 2018, 7:34 PM
Michael Simnitt
Michael Simnitt - avatar
+ 2
the answer I gave you should have solved this other than that are you just looking for someone to write the algorithm for you?
28th Feb 2018, 4:33 PM
Michael Simnitt
Michael Simnitt - avatar
+ 1
Steps : 1) Sort the list of weights and prices according to the criteria (keep more expensive and less weighing items on top). 2) Add the items from the top to the thief's bag till 79 weight units are reached. Can you provide a sample answer to compare? Maybe for the case you posted?
27th Feb 2018, 3:29 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
0
thief wants the precise answer which is the best one know think, and reply me an structure of it, this is a sample of problem, actual problem is bigger than it, one more thing if we set loop it will run a 2^11 iterations, which will take a huge time..., so make an algorithm to solve the problem. you can also email me @ naeem1098@gmail.com
28th Feb 2018, 1:44 PM
Muhammad Naeem Jamali
Muhammad Naeem Jamali - avatar
0
no thanx Michael.
1st Mar 2018, 10:18 AM
Muhammad Naeem Jamali
Muhammad Naeem Jamali - avatar