A simple riddle express this week on The Riddler, about finding the years between 2001 and 2099 with the most cases when day x month = year [all entries with two digits]. For instance, this works for 1 January, 2001 since 01=01 x 01. The only difficulty in writing an R code for this question is to figure out the number of days in a given month of a given year (in order to include leap years).
The solution was however quickly found on Stack Overflow and the resulting code is
#safer beta quantile
numOD <- function(date) {
m <- format(date, format="%m")
while (format(date, format="%m") == m) date <- date + 1
return(as.integer(format(date - 1, format="%d")))
}
dayz=matrix(31,12,99)
for (i in 2001:2099)
for (j in 2:11)
dayz[j,i-2000]=numOD(as.Date(
paste(i,"-",j,"-1",sep=""),"%Y-%m-%d"))
monz=rep(0,99)
for (i in 1:99){
for (j in 1:12)
if ((i==(i%/%j)*j)&((i%/%j)<=dayz[j,i]))
monz[i]=monz[i]+1}
The best year in this respect being 2024, with 7 occurrences of the year being the product of a month and a day…