Kaperkar’s Constant

I was recently introduced to Kaperkar’s Constant.
It is quite magical. You take any four digit number A, sort the digits from highest to lowest to create a new number A^{\text{high}}, sort the digits from lowest to highest to get A^{\text{low}}, and calculate and new number A= A^{\text{high}}- A^{\text{low}}. You repeat this procedure enough times and you end up with A=6174.

I made a nifty implementation of that in Julia below.


Monkeys and Coconuts

Here is my attempt to solve the monkeys and coconuts problem. The story goes
that five sailors were stranded on an island and had decided to gather some
coconuts for their provisions. They put all the coconuts in one large pile and
went to sleep. One sailor got up and fearing that there could be problems when the
time to came to divide the pile, he divided the pile five ways and noticing that
he has an extra coconut, he gave it to a monkey, and then hid his stash. The other
four sailor repeated the same procedure. When they woke up they noticed that
they had a smaller pile and proceeded to divide into five equal piles, this time
around there were no extra coconut left for the monkey. So the question is: what was
the size of the original pile?

We will denote by x_i as the size of the
pile after the ith sailor has carried out his procedure. In this system x_0
is original size of the pile. So following this procedure we then proceed as


It is important to note that x_i \in \mathbb{N}_0 for i=0\ldots5, also \frac{x_5}{5}\in \mathbb{N}_0. Alternatively, we think of the reverse procedure and express the above as

Observing that x_5 has to be divisible by 4 and 5 (last equation in the first system and first equation in the second), one can brute force the solution(s) by the following Julia code:

Which results in

m=51, x₀= 3121
m=307, x₀= 18746
m=563, x₀= 34371
m=819, x₀= 49996

This corresponds nicely to the answers that were obtained by rigorous derivation in the video, however it shows how programming can easily find such solutions by brute force.

If one would like to avoid the negative or blue concocts suggested in the video and also preserve the monkey. Below is an alternative derivation. Working through the first system, one gets:

x_{5}={{4\,\left({{4\,\left({{4\,\left({{4\,\left({{4\,\left(x_{0}-  1\right)}\over{5}}-1\right)}\over{5}}-1\right)}\over{5}}-1\right)  }\over{5}}-1\right)}\over{5}}=\frac{4^5x_0}{5^5}-\frac{8404}{5^5}

Realizing the x_5 has to be necessarily divisible by 5, we denote the final share that each sailor gets in the last division by s. So our Diophantine equation becomes
It will have solutions at x_0=3121, 18746, 34371 \ldots= 3121+n5^6 \text{ for } n \in \mathbb{N}_0 .


Mathematical Distractions

While attending a conference and hanging out with a college later in the day he recounted to me a nice mathematical puzzle that he learned while growing up in Algeria.
Puzzle 1:
Three brothers were in a bind, they could not divide their father’s inheritance. Their father has left them with 17 camels and instructions that half of his camels should go to eldest son, a third to the second eldest, and a ninth to the youngest. Knowing that there is no point in having a fraction of camel, they wanted a solution that would be fair and yet that would result in no fractional division of camels. A passerby, seeing their predicament proposed to help.
In order to resolve their problem he donated his camel to the pool of 17 camels, bring thus the total to 18. One brother will hence get 9 camels, the other would get 6, and the youngest would get 2 camels. But 9+6+2=17, therefore the passerby concluded that he would walk away with the left over camel. Problem solved… but how?
Puzzle 2:
Two farmers decided to sit down and share their lunch food. One farmer had on him five loafs of bread and the other had seven loafs. Just as they were about to start, a passerby asked if he could join them. The three sat down and they equally divided the twelve loafs amongst themselves. When they were done, the passerby give them twelve dirhams for the meal. The farmer who contributed five loafs proposed that a fair division of that amount would be for him to take five dirhams and for the other farmer to take the remaining seven. A disagreement ensued. They sought the assistance of judge to resolve their disupte and his resolution was that the farmer who contributed five loafs should only walk away with three dirhams, while the other should have the remaining nine dirhams. How is this fair?