## one-way random walks

Posted in Kids, R, Statistics with tags , , , on May 2, 2021 by xi'an

A rather puzzling riddle from The Riddler on an 3×3 directed grid and the probability to get from the North-West to the South-East nodes following the arrows. Puzzling because while the solution could be reasonably computed with an R code like

sucz=0
for(i in 1:2^12){
path=intToBits(i)[1:12]
sol=0
for(j in 1:12)sol=max(sol,
prod(path[paz[[j]][paz[[j]]>0]]==01)*
prod(path[-paz[[j]][paz[[j]]<0]]==00))
sucz=sucz+sol


where paz is the list of the 12 possible paths from North-West to South-East (excluding loops!), leading to a probability of 1135/2¹², I could not find a logical reasoning to reach this number. The paths of length 4, 6, 8 are valid in 2⁸, 2⁶, 2⁴ of the cases, respectively and logically!, but this does not help as they are dependent.

## Take thrice thy money, bid me tear the bond

Posted in Books, Kids with tags , , , , , on April 21, 2021 by xi'an

A rather fun riddle for which the pen&paper approach proved easier than coding in R, for once. It goes as follows: starting with one Euro, one sequentially predicts a sequence of four random bits, betting an arbitrary fraction of one’s money at each round. When winning, the bet is doubled, otherwise, it is lost. Under the information that the same bit cannot occur thrice in a row, what is the optimal minimax gain?

Three simplifications: (i) each bet is a fraction ε of the current fortune of the player, which appears as a product of (1±ε) the previous bets (ii) when the outcome is 0 or 1, this fraction ε can thus be chosen in (-1,1), (iii) while the optimal choice is ε=1 when the outcome is known, i.e., when both previous are identical. The final fortune of the player is thus of the form

(1±ε)(1±ε’)(1±ε”)(1±ε”’)

if the outcome is alternating (e.g., 0101 or 0100), while it is of the form

2(1±ε)(1±ε’)(1±ε”)

if there are two identical successive bits in the first three results (e.g., 1101 or 0110). When choosing each of the fractions ε, the minimum final gain must be maximised. This implies that ε=0 for the bet on the final bit  when the outcome is uncertain (and ε=1 otherwise). In case of an alternating début, like 01, the minimal gain is

min{(1±ε)(1±ε’)(1+ε”),2(1±ε)(1±ε’)(1-ε”)}

which is maximised by ε”=1/3, taking the objective value 4(1±ε)(1±ε’)/3. Leading to the gain after the first bit being

min{4(1±ε)(1+ε’)/3,2(1±ε)(1-ε’)}

which is maximised by ε’=1/5, for the objective value 8(1±ε)/5. By symmetry, the optimal choice is ε=0. Which ends up with a minimax gain of 3/5. [The quote is from Shakespeare, in the Merchant of Venice.]

## baby please don’t cry

Posted in Statistics with tags , , , , on April 9, 2021 by xi'an

First, an express riddle from the Riddler of last week:

An infant naps peacefully for two hours at a time and then wakes up, crying, due to hunger. After eating quickly, the infant plays alone for another hour, and then cries due to tiredness. This cycle repeats over the course of a 12-hour day. (The baby sleeps peacefully 12 hours through the night.) At a random time during the day, you spend 30 minutes with your baby and then the baby cries. What’s the probability that your baby is hungry?

The probabilistic setting is somewhat unclear, in particular because the last daytime nap is followed immediately with a 12 hour night sleep. Or the 12 hour night sleep is immediately followed by a one or two hour nap. Assuming a random starting time over the 12 hour period, denoting X as the time to the next crisis and Y as the nature of the cries (H versus T), it is straightforward to show that P(Y=H|X=30′) is ½. While it would be 1 for any duration larger than one hour.

Followed by an extra one this week:

Starting at a random time, 30 minutes go by with no cries. What is the probability that the next time your baby cries she will be hungry?

Which means computing P(Y=H|X>30′). Equal to ¾ in this case.

## plusquamperfect squares

Posted in Books, Kids, R with tags , , , on April 2, 2021 by xi'an

For some perfect squares, when you remove the last digit, you get another perfect square. The first five perfect squares are 16, 49, 169, 256 and 361. What are the next three ones? Is there a more than perfect square other than 169 such that removing the last two digits returns a perfect square?

Writing an R code for plusquamperfect squares is straightforward and returns the following first 20 values

 [1]         16         49        169        256        361       1444
[7]       3249      18496      64009     237169     364816     519841
[13]    2079364    4678569   26666896   92294449  341991049  526060096
[19]  749609641 2998438564


Adding the second constraint does not return a solution other than 169.

$\left|\frac{1}{N-j} \sum_{i=j+1}^N x_i -x_j\right|>1$
$\max_{2\le j\le N-1} \left|\frac{1}{N-j} \sum_{i=j+1}^N \sum_{k=j+1}^i\epsilon_i \right|>1$