library(tidyverse)
tibble(y = 1:2020) |>
mutate(r = as.roman(y),
l = str_length(r)) |>
slice_max(l)
# A tibble: 1 × 3
y r l
<int> <roman> <int>
1 1888 MDCCCLXXXVIII 13
Michaël
2020-12-25
2024-12-25
What is the longest year number (yet) written in Roman numerals?
# A tibble: 1 × 3
y r l
<int> <roman> <int>
1 1888 MDCCCLXXXVIII 13
It is year 1888, with 13 characters…
And the largest writable number being 3899, according to the strict rules in R (however some say it’s 3999),
tibble(y = 1:5000) |>
mutate(r = as.roman(y),
l = str_length(r)) |>
filter(lead(is.na(l))) |>
slice_min(l)
# A tibble: 1 × 3
y r l
<int> <roman> <int>
1 3899 MMMDCCCXCIX 11
the longest overall year will be year 3888 with 15 characters.
# A tibble: 1 × 3
y r l
<int> <roman> <int>
1 3888 MMMDCCCLXXXVIII 15
Nice pattern:
tibble(y = 1:3899) |>
mutate(r = as.roman(y),
l = str_length(r)) |>
ggplot(aes(y, l)) +
geom_point(alpha = .2) +
geom_smooth() +
labs(title = "Characters length of roman numeral years",
x = "year",
y = "characters")
And there are only eleven palindromic years:
tibble(y = 1:3899) |>
mutate(r = as.character(as.roman(y)),
rr = stringi::stri_reverse(r)) |>
filter(r == rr,
str_length(r) > 1)
# A tibble: 11 × 3
y r rr
<int> <chr> <chr>
1 2 II II
2 3 III III
3 19 XIX XIX
4 20 XX XX
5 30 XXX XXX
6 190 CXC CXC
7 200 CC CC
8 300 CCC CCC
9 1900 MCM MCM
10 2000 MM MM
11 3000 MMM MMM
---
title: "Playing with Roman numerals"
description: ""
author: "Michaël"
date: "2020-12-25"
date-modified: last-modified
categories:
- R
draft: false
freeze: true
editor_options:
chunk_output_type: console
---
What is the longest year number (yet) written in Roman numerals?
```{r}
library(tidyverse)
tibble(y = 1:2020) |>
mutate(r = as.roman(y),
l = str_length(r)) |>
slice_max(l)
```
It is year 1888, with 13 characters...
And the largest writable number being 3899, according to the strict rules in R (however [some say](https://en.wikipedia.org/wiki/Roman_numerals#Standard_form) it's 3999),
```{r}
tibble(y = 1:5000) |>
mutate(r = as.roman(y),
l = str_length(r)) |>
filter(lead(is.na(l))) |>
slice_min(l)
```
the longest overall year will be year 3888 with 15 characters.
```{r}
tibble(y = 1:3899) |>
mutate(r = as.roman(y),
l = str_length(r)) |>
slice_max(l)
```
Nice pattern:
```{r}
tibble(y = 1:3899) |>
mutate(r = as.roman(y),
l = str_length(r)) |>
ggplot(aes(y, l)) +
geom_point(alpha = .2) +
geom_smooth() +
labs(title = "Characters length of roman numeral years",
x = "year",
y = "characters")
```
And there are only eleven palindromic years:
```{r}
tibble(y = 1:3899) |>
mutate(r = as.character(as.roman(y)),
rr = stringi::stri_reverse(r)) |>
filter(r == rr,
str_length(r) > 1)
```