Let’s Go to Rome

July 25, 2013
By

(This article was first published on Frank Portman, and kindly contributed to R-bloggers)

Although virtually obsolete, Roman Numerals are subtly embedded into our culture. From the Super Bowl and Olympics to royal titles, Roman Numerals refuse to fully be extinguished from our every day lives. And that’s not without reason. All numbers are beautiful and Roman Numerals are no exception, even if they are written a little differently from their Arabic counterparts.

In this post, we’ll examine some fascinating properties of Roman Numerals – namely the lengths of Roman Numerals in succession.

First, we define a simple Arabic –> Roman Numeral converter. Start by creating two vectors, one for the 13 Roman symbols and another for the Arabic counterparts. Next, a simple for/while combination iterates through the arrays and chooses the appropriate Roman symbols while iteratively decreasing the input variable.


1
2
3
4
5
6
7
8
9
10
11
12
13
arabic <- c(1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
roman <- c("M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I")

toRoman <- function(n) {
  ans <- c()
  for(i in 1:length(arabic)) {
    while(n >= arabic[i]) {
      ans <- c(ans, roman[i])
      n <- n - arabic[i]
    }
  }
  ans
}

Next we want to find the lengths of each of these representations:


1
2
3
4
5
6
cands <- list()
cands[1:3999] <- 1:3999
cands <- lapply(cands, toRoman)
cands <- lapply(cands, function(x) unlist(strsplit(x, "")))
lens <- lapply(cands, length)
lens <- as.numeric(lens)

Finally, plot the result:


1
2
3
4
qplot(1:3999, lens, geom = "line") + xlab("Numbers") +
  ylab("Length of Roman Numeral") +
  ggtitle("1 - 3999 Length of Roman Numerals") +
  geom_smooth(method = "lm")

What a fascinating relationship! The lengths seem to take a sinusoidal shape with positive drift. We can see that although the average length keeps rising, the plot goes through very regular cycles of rising and falling.

To leave a comment for the author, please follow the link and comment on their blog: Frank Portman.

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...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)