## Archive for 2020

## on the edge of starvation

Posted in Kids, pictures, Travel with tags 2020, donation, hunger, Nobel Peace Prize, starvation, UN, United Nations, United Nations World Food Programme, Yemen on October 18, 2020 by xi'an## meals that make a difference

Posted in Kids, pictures, Travel with tags 2020, campaign, hunger, Nobel Peace Prize, school meals, UN, United Nations World Food Programme, WFP on October 11, 2020 by xi'an## Le Monde puzzle [#1146]

Posted in Books, Kids, R with tags 2020, brute-force solution, code golf, dynamic programming, Gare d'Austerlitz, Le Monde, mathematical puzzle, Paris, R on June 5, 2020 by xi'an**T**he weekly puzzle from Le Monde is once more disappointing.

Everyday of the month, take 0, 1 or 2 units. If one unit taken past day, next day none can be taken. If two units taken two day ago, none can be taken the current day. What is the strategy maximising the number of units for February? March? April? Generalise to 0,..,3 units taken each day with 0 compulsory three days after taking 3 units.

as taking 2-1-0 (or 3-2-1-0) sounds like the optimal strategy. Except at the final step when 2, 2-2, 2-2-0, and 1-0-2-2 are best. But then why would one distinguish between the three months..?! Because the outcome differ, as 30, 32, and 33, resp. (or 45, 48 and 51). With an average increase of 1 in the first case and 1.5 in the second.

Another puzzle took too much of my time, namely a code golf challenge to devise a code taking as input a matrix of moves over an n x x grid and returning as input the number of nodes and transient tributaries for each loop (or irreducible set) of the moves. Which I solved by running Markov chains from each starting point long enough to reach stationarity. Entering the moves as

n=3;M=matrix(sample(1:4,n^2,rep=T),n)

and returning the result via 390 bytes

j=cbind;l=sum;a=apply m=l(!!M);n=m^.5 g=function(A,r=M[A])A+c((r<2)*(1-n*(A[,1]==n))-(r==2)*(1-n*(A[,1]<2)), (r==3)*(1-n*(A[,2]==n))-(r>3)*(1-n*(A[,2]<2))) I=c() for(i in d<-1:n)I=rbind(I,j(i*d/d,d)) for(t in b<-1:m)I=g(I) p=function(i)i[,1]+n*i[,2]-n-1 K=matrix(0,m,m) for(t in b)K[b+m*p(I<-g(I))]=1 s=o=a(u<-unique(K),1,l) for(k in 1:l(!!s))s[k]=l(!a(!!sweep(K,2,u[k,],'-'),1,l)) j(o,s-o)

which could be much shorter if only matrices could be indexed from 0 as in C.

## Le Monde puzzle [#1144]

Posted in Books, Kids with tags 2020, brute-force solution, Gare d'Austerlitz, Le Monde, mathematical puzzle, Paris, R on May 19, 2020 by xi'an**T**he weekly puzzle from Le Monde is again using 2020 but not R!

Two teams involve a prime total number m of participants, with each player getting between 0 and 100 points. The total score for both teams is 2020, with team B less than team A on average. A single transfer from A to B increases the average scores for both A and B by 1/2. What is the difference of the averages? The transfer(ed) player, Camélia, had 5 points less than the average score for A. What was the score of Camélia?

but I could not find a brute force solution and ended up finding that 2×2020=2x2x5x101 is a multiple of m, which leaves only

m=101

as the possible number of players. Which almost immediately leads to a difference of m/2 between the average scores. And then almost as immediately to Camélia’s score being 60. If one really needed an R function

k=function(a){((C<-71-a)>0)&(C+(a-1)/2<102) &(C-((102-a)/2)>0)&(C+5==(C+(a-1)/2))}

does return a=11 but this is 100% useless!