# no country for old liars

March 29, 2019
By

(This article was first published on R – Xi'an's Og, and kindly contributed to R-bloggers)

A puzzle from the Riddler about a group of five persons, A,..,E, where all and only people strictly older than L are liars, all making statements about others’ ages:

1. A: B>20 and D>16
2. B: C>18 and E<20
3. C: D<22 and A=19
4. D: E≠20 and B=20
5. E: A>21 and C<18

The Riddler is asking for the (integer value of L and the ranges or values of A,…,E. After thinking about this puzzle over a swimming session, I coded the (honest) constraints and their (liar) complements as many binary matrices, limiting the number of values of L to 8 from 0 (15) to 7 (22) and A,…,E to 7 from 1 (16) to 7 (22):

```CA=CB=CC=CD=CE=A=B=C=D=E=matrix(1,5,7)
#constraints
A[2,1:(20-15)]=A[4,1]=0 #A honest
CA[2,(21-15):7]=CA[4,2:7]=0 #A lying
B[3,1:(18-15)]=B[5,(20-15):7]=0
CB[3,(19-15):7]=CB[5,1:(19-15)]=0
C[1,-(19-15)]=C[4,7]=0 #C honest
CC[1,(19-15)]=CC[4,-7]=0 #C lying
D[5,(17-15)]=D[2,-(20-15)]=0
CD[5,-(17-15)]=CD[2,(20-15)]=0
E[1,1:(21-15)]=E[3,(18-15):7]=0
CE[1,7]=CE[3,1:(17-15)]=0
```

since the term-wise product of these five matrices expresses all the constraints on the years, as e.g.

```ABCDE=A*CB*CC*D*CE
```

if A,D≤L and B,C,E>L, and I then looked by uniform draws [with a slight Gibbs flavour] for values of the integers that suited the constraints or their complement, the stopping rule being that the collection of A,…,E,L is producing an ABCDE binary matrix that agrees with all statements modulo the lying statuum of their authors:

```yar=1:5
for (i in 1:5) yar[i]=sample(1:7,1)
L=sample(0:7,1)
ABCDE=((yar>L)*CA+(yar<=L)*A)*
((yar>L)*CB+(yar<=L)*B)*
((yar>L)*CC+(yar<=L)*C)*
((yar>L)*CD+(yar<=L)*D)*
((yar>L)*CE+(yar<=L)*E)
while (min(diag(ABCDE[,yar]))==0){
L=sample(0:7,1);idx=sample(1:5,1)
if (max(ABCDE[idx,])==1) yar[idx]=sample(which(ABCDE[idx,]>0),1)
ABCDE=((yar>L)*CA+(yar<=L)*A)*
((yar>L)*CB+(yar<=L)*B)*
((yar>L)*CC+(yar<=L)*C)*
((yar>L)*CD+(yar<=L)*D)*
((yar>L)*CE+(yar<=L)*E)
}
```

which always produces L=18,A=19,B=20,C=18,D=16 and E>19 as the unique solution (also reported by The Riddler).

```> ABCDE
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    0    0    0    1    0    0    0
[2,]    0    0    0    0    1    0    0
[3,]    0    0    1    0    0    0    0
[4,]    1    0    0    0    0    0    0
[5,]    0    0    0    0    1    1    1
```

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...