Problem # 31 : Mustapha's herd

There is an old story about an old merchant who had 3 sons and 17 camels. It was his wish that on his death the eldest son was to receive one-half (1/2) of his camels, the next son was to receive one-third (1/3) of his camels and the youngest son one-ninth (1/9).

When the sad day came to divide up the old merchant's herd in accordance with his wishes, there was a problem as none of the sons wanted part of the camel, nor would they give up part of a camel to one of their brothers.

The problem was solved by a wise man who lived in the village. He came to the merchant's house and brought a camel with him, which he added to the merchant's herd. Now the eldest son was able to take half of 18 camels - 9, the middle son one-third - 6 and the youngest son could take one-ninth - 2 camels. Moreover, because 9 + 6 + 2 = 17, the wise man was able to take his own camel home with him.

There is a more modern story about Mustapha, a Bedouin chieftan and his best friend, Ali. Mustapha was seriously injured. While lying in what was likely to be his deathbed, Mustapha confided to Ali that he had always enjoyed the old story. As he also had three sons, Mustapha wished to divide his herd of camels amongst his sons in such a way that the story would work for him as well. However, there were two problems, Mustapha had promised his own dying father that he would never sell a camel from the herd, and Mustapha had 39 camels, NOT 17.

Mustapha asked Ali to help him find out if it was possible to use a different way of sharing animals that would still work in the way of the old story. Mustapha said he would be happy to buy some extra camels as long as they could work out how many he needed.

Between them, Mustapha and Ali came up with the following rules :

Write a sub-routine CAMELS, that takes as a parameter the present number of camels in a herd, and calculates the minimum number of camels there should be for the story to work, and what the shares for each of the three sons should be. Out of respect for Mustapha's father's memory, the number of camels cannot be decreased from the present size. That is, the number of camels needed must be equal to, or greater than, the present number of camels in the herd.

The sub should display all relevent information in a nicely formatted manner on a cleared screen, and if no solution is possible it should print "NO POSSIBLE SOLUTION".

Sample Output
CAMELS(17) should print the following on a cleared screen :


Present size of herd : 17
Number of camels to add : 0
 
Eldest son's share : 1/2 = 9
Middle son's share : 1/3 = 6
Youngest son's share : 1/9 = 2
******************************
Number of camels shared = 17

Previous Problem
Return to problems at The Vault
(Back to problems at The Vault )
Next Problem

LinkExchange
LinkExchange Member
1