Archive for mathematical puzzle

common leftovers

Posted in pictures, Travel with tags , , , , on April 5, 2023 by xi'an

The Riddler was about a number game, which meant starting a sum at 0 and adding i to the current sum at time i, almost a Fibonacci sequence but not exactly, since the sequence is simply

u_i=\dfrac{i(i+1)}{2}

which is easy to code, is of period 200, and this code showed that 3, 28, 53, and 78 were the most frequent last two digits. Or all 3 modulo 25 digits.

alone in Napoli

Posted in Books, Kids, R, Statistics with tags , , , , , , , , on March 13, 2023 by xi'an


A combinatorics puzzle from The Riddler about a Napoli solitaire where 4 x 10 cards numbered from 1 to 10 are shuffled and the game is lost when a number (1,2, or 3) is equal to its position modulo 3 (1,2 or 3). A simple R code shows that the probability of winning is around 0.00831:

N=40
for(t in 1:1e6)F=F+!sum(!(sample((1:N)%%10)-(1:N)%%3))

ChatGPT bends over backward to achieve this figure! Now, the exact probability can be found by combinatorics. While there are 40! ways of permuting the 40 cards, those missing the coincidences are

\sum\limits_{k=0}^4\sum\limits_{j=0}^4\sum\limits_{i=0}^4{13\choose i}{13\choose 4-i}{14\choose j}{13-i\choose 4-j}{14-j\choose k}{9+i\choose 4-k}

multiplied by 4!4!4!28! (which I initially forgot), resulting in 0.00831:

for(i in 0:4)for(j in 0:4)for(k in 0:4)
      F=F+exp(lchoose(13,i)+lchoose(13,4-i)+3*lfactorial(4)+
          lchoose(14,j)+lchoose(13-i,4-j)+lfactorial(28)+
          lchoose(14-j,k)+lchoose(9+i,4-k)-lfactorial(40))

Diophantine riddle

Posted in Books, Kids, R with tags , , , , , , , on February 27, 2023 by xi'an

The weekly riddle from The Riddler is to find solutions to the Diophantine equation

c³-c=b²+4

(when b and c are positive integers). First, forget about ChatGPT since it states this is a Pell equation. With a wrong argument. Second, when running a basic R code, using as.double to handle larger integers, the only solution less than 10⁶ this code returned was

[1]    999799 999700015

with the first column being c and the second b. But this is not a correct solution!, as confirmed by Mathematica, which states there is no integer solution. This makes sense when looking at the unique real solution (in c) of the cubic

c³-c-(b²+4)=0

since the solution (using Cardano’s formula) involves

\sqrt[3]{\frac{b^2+4}{2}\pm\sqrt{\frac{(b^2+4)^2}{4}-\frac{1}{27}}}

leaving the inverse of 27 as the only non-integer term in the expression when b is even… (The exact solution that this Diophantine equation has no solution is simpler: the lhs is a multiple of 3, while the rhs cannot be, as shown by looking at b(3).)

go forth and X [or the reverse]

Posted in Books, Kids with tags , , , , on February 8, 2023 by xi'an

The New Year Riddle is about optimisation: starting with a single machine, between delivering one unit per machine – hour and delivering one new machine per machine every six days, what is the maximal number of units produced over 100 days?

Comparing the amounts produced by k machines after 6log2(k) days used to multiply the machines showed that 2¹⁵ -1 additional machines were first produced, to generate 7864320 items over the remaining 10 days. Which did not really require an R implementation (although I checked that intermediate solutions where only some of the machines were producing new machines were sub-optimal).

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,]))