Let’s Go to Rome

[This article was first published on Frank Portman, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)