<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/a-gregorian-calendar-riddle/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://xianblog.wordpress.com/2018/04/17/a-gregorian-calendar-riddle/"> R – Xi'an's Og</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong><a rel="nofollow" href="https://xianblog.files.wordpress.com/2018/04/riddler0407.jpg" target="_blank"><img data-orig-file="https://xianblog.files.wordpress.com/2018/04/riddler0407.jpg" data-orig-size="480,480" data-medium-file="https://xianblog.files.wordpress.com/2018/04/riddler0407.jpg?w=300&amp;h=300&amp;fit=300%2C300&amp;resize=300%2C300" data-attachment-id="35865" data-image-meta="{" data-image-description="" src="https://xianblog.files.wordpress.com/2018/04/riddler0407.jpg?w=300&h=300&fit=300%2C300&resize=300%2C300" data-permalink="https://xianblog.wordpress.com/2018/04/17/a-gregorian-calendar-riddle/riddler0407/" data-large-file="https://xianblog.files.wordpress.com/2018/04/riddler0407.jpg?w=450" alt="" data-image-title="riddler0407" sizes="(max-width: 300px) 100vw, 300px" width="300" data-comments-opened="1" class="wp-image-35865" data-recalc-dims="1" height="300"></a>A</strong> simple <a rel="nofollow" href="https://fivethirtyeight.com/features/when-will-the-arithmetic-anarchists-attack/" target="_blank">riddle express</a> this week on <a rel="nofollow" href="https://fivethirtyeight.com/features/a-riddle-how-many-crooked-politicians-are-there/" target="_blank">The Riddler</a>, 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).</p>
<p>The solution was however quickly found on <a rel="nofollow" href="https://stackoverflow.com/a/6243306/1154578" target="_blank">Stack Overflow</a> and the resulting code is</p>
<pre>#safer beta quantile
numOD &lt;- function(date) {
    m &lt;- format(date, format=&quot;%m&quot;)
    while (format(date, format=&quot;%m&quot;) == m) date &lt;- date + 1
    return(as.integer(format(date - 1, format=&quot;%d&quot;)))
}
dayz=matrix(31,12,99)
for (i in 2001:2099)
for (j in 2:11)
  dayz[j,i-2000]=numOD(as.Date(
  paste(i,&quot;-&quot;,j,&quot;-1&quot;,sep=&quot;&quot;),&quot;%Y-%m-%d&quot;))

monz=rep(0,99)
for (i in 1:99){
for (j in 1:12)
  if ((i==(i%/%j)*j)&amp;((i%/%j)&lt;=dayz[j,i])) 
    monz[i]=monz[i]+1}
</pre>
<p>The best year in this respect being 2024, with 7 occurrences of the year being the product of a month and a day…</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://xianblog.wordpress.com/2018/04/17/a-gregorian-calendar-riddle/"> R – Xi'an's Og</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/Pe0LxdS_lx0" height="1"></a></div>