Archive for The Riddler

Tribonacci sequence

Posted in Books, Kids, R with tags , , , , , on January 3, 2023 by xi'an

A simplistic puzzle from The Riddler when applying brute force:

A Tribonacci sequence is based on three entry integers a ≤ b ≤ c, and subsequent terms are the sum of the previous three. Among Tribonacci sequences containing 2023, which one achieves the smallest fourth term, a+b+c ?

The R code

tri<-function(a,b,e){
  while(F<2023){
  F=a+b+e;a=b;b=e;e=F}
  return(F<2024)}
sol=NULL;m=674
for(a in 1:m)
  for(b in a:m)
    for(e in b:m)
     if(tri(a,b,e)){
       sol=rbind(sol,c(a,b,e))}

leads to (1,1,6) as the solution… Incidentally, this short exercise led me to finally look for a fix to entering vectors as arguments of functions requesting lists:

do.call("tri",as.list(sol[2023,]))

foliage to the max

Posted in Books, Kids, pictures with tags , , , , , on December 17, 2022 by xi'an

An easy riddle from The Riddler that did not even require coding! Given that a tree changes colours at a random time A distributed according to a Uniform distribution (over (0,1)) and that it sheds its leave at a random time B distributed according to a Uniform distribution (over (A,1)), what is the time when a maximal number of trees show their new colour?

Which means optimising in t the probability that A<t<B. Which is equal to -(1-t)log(1-t) and maximal for t=1-e⁻¹, resulting in a (maximal) fraction of e⁻¹ of the trees holding to their new colour at that time.

Bertrand’s tartine

Posted in Books, Kids, pictures, Statistics with tags , , , , , , , , , , on November 25, 2022 by xi'an

A riddle from The Riddler on cutting a square (toast) into two parts and keeping at least 25% of the surface on each part while avoiding Bertrand’s paradox. By defining the random cut as generated by two uniform draws over the periphery of the square. Meaning that ¼ of the draws are on the same side, ½ on adjacent sides and again ¼ on opposite sides. Meaning one has to compute

P(UV>½)= ½(1-log(2))

and

P(½(U+V)∈(¼,¾))= ¾

Resulting in a probability of 0.2642 (checked by simulation)

another drawer of socks

Posted in Books, Kids, R, Statistics with tags , , , , , , on November 6, 2022 by xi'an

A socks riddle from the Riddler but with no clear ABC connection! Twenty-eight socks from fourteen pairs of socks are taken from a drawer, one by one, and laid on a surface that only fit nine socks at a time, with complete pairs removed. What is the probability that all pairs are stored without running out of space? No orphan socks then!!

Writing an R code for this experiment is straightforward

for(v in 1:1e6){
 S=sample(rep(1:14,2))
 x=S[1]
 for(t in 2:18){
  if(S[t]%in%x){x=x[S[t]!=x]}else{x=c(x,S[t])}
  if(sum(!!x)>9){
    F=F+1;break()}}}

and it returns a value quite close to 0.7 for the probability of success. I was expecting a less brute-force resolution but the the Riddler only provided the answer of 70.049 based on the above tree of probabilities (which I was too lazy to code).

birthday paradox, one by one

Posted in Books, Kids, pictures, Statistics with tags , , , , , on November 1, 2022 by xi'an

An easy riddle, riding the birthday paradox. Namely how many people on average have to sequentially enter a room for a double birthday to occur?

The answer is straightforward,

\sum_{n=2}^{366}n\prod_{m=1}^{n-2}\left(1-\frac{m}{365}\right)\frac{n-1}{365}

as only the last person in can share a birthday with those already in. This sum equals 24.62. Since the “magic number” is 23, this may sound wrong but the median attached to the above distribution is truly 23. My R code is

q=rep(1,a<-366)/365
for(n in 3:a)q[n]=q[n-1]*(1+1/(n-2)-(n-1)/365)
sum(q[-1]*(2:a))
%d bloggers like this: