riddles on a line
This article is originally published at https://xianblog.wordpress.com
In the Riddler of August 18, two riddles connected with the integer set Ð={2,3,…,10}:
- Given a permutation of Ð, what is the probability that the most likely variation (up or down) occurs at each term?
- Given three players choosing three different integers in Ð sequentially, and rewards in Ð allocated to the closest of the three players (with splits in case of equal distance), what is the reward for each given an optimal strategy?
For the first question, a simple code returns 0.17…
winofail<-function(permz){ if (length(permz)>1){ lenoperm=length(permz[-1])/2 win=(permz[1]<permz[2])*(sum(permz[-1]>permz[1])>lenoperm)+ (permz[1]>permz[2])*(sum(permz[-1]<permz[1])>lenoperm)+ (runif(1)<.5)*(sum(permz[-1]>permz[1])==lenoperm) win=win&&winofail(permz[-1]) }else win=TRUE return(win)}
and for the second question, a quick recursion produces 17, 18, 17 as the rewards
gainz<-function(seqz){ difz=t(abs(outer(2:10,seqz,"-"))) cloz=apply(difz,2,rank) return(apply((2:10)*((cloz==1)+.5*(cloz==1.5),1,sum))} timeline<-function(prev){ if (length(prev)==0){ sol=timeline(10);bez=gainz(sol)[1] for (i in 2:9){ bol=timeline(i);comp=gainz(bol)[1] if (comp>bez){ bez=comp;sol=bol}}} if (length(prev)==1){ bez=-10 for (i in (2:10)[-(prev-1)]){ bol=timeline(c(prev,i)) comp=gainz(bol)[2] if (comp>bez){ bez=comp;sol=bol}}} if (length(prev)==2){ bez=-10 for (i in (2:10)[-(prev-1)]){ bol=c(prev,i) comp=gainz(bol)[3] if (comp>bez){ bez=comp;sol=bol}}} return(sol)}
Thanks for visiting r-craft.org
This article is originally published at https://xianblog.wordpress.com
Please visit source website for post related comments.