+ 5
CHALLENGE :- Can a program help to solve this bain storming question??
Once a Mango seller went for selling mangoes and in hurry he took only 50 kg weight with him in the van. When customer asked for mangoes less than 50kg ,he cannot weigh it , since he had only 50kg weight. He was irritated and he threw 50kg weight on ground and it broke up into 5 pieces(5 parts are in whole no.). He was so lucky that all these 5 piece , he managed to give mangoes weighing between 1kg & 50kg (whole no.s)to customers by weighing once. What are the 5 parts in which weight was broken up???
16 Answers
+ 4
question not clear to me, did u knew the weights of all 5 pieces, give a sample example to weight if I want 14 kg mangoes
+ 4
@Rahul Jaiswal, thx for the explanation, now I can have some depth perception about the ingenuity of Gordie's solution since it's marked right.( đ can't read ruby though) . I ll try this challenge , it's cool like one of those optimization problems that gives me nightmares and mks me wanna quit programmingđ
+ 3
so What is the answer you are getting
+ 3
Thanks bro ,it workedđđ đ€đđ
+ 3
Could you help me write a similar code in java or C or C++.
+ 3
Java is my best, you can check my profile
+ 3
how this ruby code is working , I am not getting it at all, little bit of explanation for this or a hint ,how to do it in C or java will do the work
+ 3
Thanks alot , now I got it & can write the code in java and c.
But Ruby is really amazing , all these tasks in just few lines.
+ 3
Here is my try in java , this works for any weight you want. :-
https://code.sololearn.com/cj1bh1DUuvKs/?ref=app
To get the output for this ,give input 50
+ 2
@ Morpheus Suppose you divided the weights into 3,4,11,12,20(sum=50) , now you can give 14 kg mangoes by keeping 11 & 3kg at one end , 1 kg by keeping 12 at one end & 11 at other, etc.
But with these 5 parts , you can't give all quantities from 1 to 50 , like 49, etc. So your task is to find out that 5 parts which will give all from 1to 50.