100 Cows and milk distribution puzzle
Read Time: 1 min 52 sec.
Read Time: 1 min 52 sec.
A milkman has 100 cows number from 1 to 100. Every cow gives milk according to their numbers i.e i'th cow gives i litre milk. Milkman has 10 sons and he wants to divide his cows among his 10 sons so that every son should get an equal amount of milk, the task is to help him to know about the division of these cows among the sons.
The solution is pure logic based and I found this in some internet but I improvised it and made the formula for all the general cases. So, lets start with the logic I found on internet (in this case it is geeksforgeeks.org). My way of approach towards the problem is different I analyze and I understand the missing parts, find solution and improvise for the general case. Same I have done here.
keywords: pairing, arithmetic progression
As we know that the i'th cow gives i litres milk. So first let us count the total litre of milk which is obtained from these cows. This can be solved by using arithmetic progression sum.
We know that sum of n numbers starting from 1 is always, sum = n*(n+1)/2 .
So the total quantity of milk obtained if from 100 cows is total milk = 100(100+1)/2=5050 litres.
As the problem says that the division of the cows should be done in a manner that every son get equal amount of milk. So every son should get 5050/10 = 505 litres of milk.
Now our main problem is to divide 1 to 100 numbers in such a way that every sons should get 10 cows who’s number sum up to 505. Here, I tried to analyze and make a generalized method of division so that the number is distributed equally at any situation. So the formula is same as above its n*(n+1)/2m where n is total number of cows and m is number of division to be made. Its not about calculating the and analyzing the amount to be shared it is how to make the division. In our case we need to analyze the distribution that every one gets the milk of 505 litres at the end of division. Which mean the sum to be 505. In my way I tried to make a division by pairs lets say n = 10 and m = 5 then the pair distribution should be as follows say the m = 5 people as {a, b, c, d, e} the distribution must be like a-(1,10), b-(2,9), c-(3,8), d-(4,7), e-(5,6). So that the numbers add up to be same in every person. Similarly in the above case the 1 st person gets (1,100), (11,90), (21,80), (31,70),(41,60) and similar till 10th person where you get (10,91),(20,81),(30,71),(40,61),(50,51). We need to consider that if the total is not divided perfectly in pairs to the number of people then the solve we made need few addition they are lets understand with an example say n = 17 and m = 5. We make the distribution in round wise say in round we distributed each pair to each in m. a-(1,17), b-(2,16), c-(3,15), d-(4,14), e-(5,13). In round two the distribution cannot be done equally in pairs as we left over with (6,12), (7,11), (8,10), 9. So in order to distribute it equally we add up everything and we divide them by m. In cows case if they are 17 cows we cannot divide the cows equally so we add up the litres of milk and divide the milk among the m = 5. The left over sum up to 63 which is divide among 5 is 12.6 so the number of litres shared to each is 12.6+1+17 = 30.6.
I even tried different possibilities with different numbers and many other options if you find any mistakes or can be able improvise the formula. Please let me know. And I need to update the code to try for higher n values. If you are trying to code use (i+1, n-i) for i in range(n) so that you can pair as I said above. I'll try to make update as soon as I get free. Thank you.