Can You Crack the Roman Code?¶

Fiddler¶

You are breaking into a vault that contains ancient Roman treasure. The vault is locked, and can be opened via a modern-day keypad. The keypad contains three numerical inputs, which are (of course) expressed using Roman numerals: “I,” “II,” and “III.”

It’s a good thing your accomplice was able to steal the numerical key code to the vault. Earlier in the day, they handed you this code on a scroll of paper. Once at the keypad, you remove the scroll from your pocket and unfurl it. It reads: “IIIIIIIIII.” That’s ten vertical marks, without any clear spacing between them.

With some quick mental arithmetic, you realize the combination to unlock the door could be anywhere from four digits long to 10 digits long. (Or is it IV digits to X digits?) How many distinct combinations are possible? If two combinations use the same numbers but in a different order, they are considered distinct.

Solution¶

I created code with a recursive function that did the following, given a string of $n$ Is :

  1. If $n = 0$, return $[[]]$ : a set containing an empty set.
  2. If $n = 1$, return $[[1]]$ : a set containing a set with I.
  3. If $n = 2$, return $[[1, 1], [2]]$ : a set containing a set for each possibility of achieving II.
  4. If $n = 3$, return $[[1, 1, 1], [1, 2], [2, 1], [3]]$ : a set containing a set for each possibility of achieving III.
  5. If $n \ge 4$ :
    1. Start with an empty list $P = []$.
    2. For each set in the result of initiating with a string of $n-1$ Is :
      1. Append 1 to the beginning of that set.
      2. Append that set to $P$.
    3. For each set in the result of initiating with a string of $n-2$ Is :
      1. Append 2 to the beginning of that set.
      2. Append that set to $P$.
    4. For each set in the result of initiating with a string of $n-3$ Is :
      1. Append 3 to the beginning of that set.
      2. Append that set to $P$.
  6. Return $P$.

Answer¶

The total number of combinations is

$$\boxed{274}$$

The sequence of number of distinct combinations of $n$ Is is a shift of Tribonacci Numbers.

Extra Credit¶

Having successfully hacked your way through the first keypad, the door opens to reveal a second door with yet another keypad that has eight numerical inputs: “I,” “II,” “III,” “IV,” “V,” “VI,” “VII,” and “VIII.”

You were expecting this, which is why your accomplice had handed you a second scroll of paper. You unfurl this one as well, hoping they remembered to add spaces between the numbers.

No such luck. This paper reads: “IIIVIIIVIIIVIII.” That’s 15 characters in total. How many distinct combinations are possible for this second door?

Solution¶

I created code with a recursive function that did the following, given a string S of a random combination of Is and Vs :

  1. If $S =$ '', return $[[]]$ : a set containing an empty set.
  2. If $S =$ I, return $[[1]]$ : a set containing a set with I.
  3. If $S =$ II, return $[[1, 1], [2]]$ : a set containing a set for each possibility of achieving II.
  4. If $S =$ III, return $[[1, 1, 1], [1, 2], [2, 1], [3]]$ : a set containing a set for each possibility of achieving III.
  5. If $S =$ IV, return $[[1, 5], [4]]$ : a set containing a set for each possibility of achieving IV.
  6. If $S =$ V, return $[[5]]$ : a set containing a set for each possibility of achieving V.
  7. If $S =$ VI, return $[[5, 1], [6]]$ : a set containing a set for each possibility of achieving VI.
  8. If $S =$ VII, return $[[5, 1, 1], [5, 2], [6, 1], [7]]$ : a set containing a set for each possibility of achieving VII.
  9. If $S =$ VIII, return $[[5, 1, 1, 1], [5, 2, 1], [5, 1, 2], [5, 3], [6, 1, 1], [6, 2], [7, 1], [8]]$ : a set containing a set for each possibility of achieving VIII.
  10. If $S$ is anything else :
    1. Start with an empty list $P = []$.
    2. If the string starts I, for each set in the result of initiating with the string starting from the second Roman Numeral :
      1. Append 1 to the beginning of that set.
      2. Append that set to $P$.
    3. If the string starts II, for each set in the result of initiating with the string starting from the third Roman Numeral :
      1. Append 2 to the beginning of that set.
      2. Append that set to $P$.
    4. If the string starts III, for each set in the result of initiating with the string starting from the fourth Roman Numeral :
      1. Append 3 to the beginning of that set.
      2. Append that set to $P$.
    5. If the string starts IV, for each set in the result of initiating with the string starting from the third Roman Numeral :
      1. Append 4 to the beginning of that set.
      2. Append that set to $P$.
    6. If the string starts V, for each set in the result of initiating with the string starting from the second Roman Numeral :
      1. Append 5 to the beginning of that set.
      2. Append that set to $P$.
    7. If the string starts VI, for each set in the result of initiating with the string starting from the third Roman Numeral :
      1. Append 6 to the beginning of that set.
      2. Append that set to $P$.
    8. If the string starts VII, for each set in the result of initiating with the string starting from the fourth Roman Numeral :
      1. Append 7 to the beginning of that set.
      2. Append that set to $P$.
    9. If the string starts VIII, for each set in the result of initiating with the string starting from the fifth Roman Numeral :
      1. Append 8 to the beginning of that set.
      2. Append that set to $P$.
  11. Return $P$.

Answer¶

The total number of combinations is

$$\boxed{4000}$$

The distribution is symmetric:

  1. A length of $4$ or $15$ have $1$ combination.
  2. A length of $5$ or $14$ have $14$ combinations.
  3. A length of $6$ or $13$ have $85$ combinations.
  4. A length of $7$ or $12$ have $295$ combinations.
  5. A length of $8$ or $11$ have $650$ combinations.
  6. A length of $9$ or $10$ have $955$ combinations.

I also found the following fascinating:

  1. IVI has $3$ combinations.
  2. IVIVI has $8$ combinations.
  3. IVIVIVI has $21$ combinations.
  4. IVIVIVIVI has $55$ combinations.
  1. IVVI has $4$ combinations.
  2. IVVIVVI has $12$ combinations.
  3. IVVIVVIVVI has $36$ combinations.
  4. IVVIVVIVVIVVI has $108$ combinations.
  1. IIVII has $10$ combinations.
  2. IIVIIVII has $50$ combinations.
  3. IIVIIVIIVII has $250$ combinations.
  4. IIVIIVIIVIIVII has $1,250$ combinations.
  1. IIVVII has $12$ combinations.
  2. IIVVIIVVII has $72$ combinations.
  3. IIVVIIVVIIVVII has $432$ combinations.
  4. IIVVIIVVIIVVIIVVII has $2,592$ combinations.
  1. IIIVIII has $40$ combinations.
  2. IIIVIIIVIII has $400$ combinations.
  3. IIIVIIIVIIIVIII has $4,000$ combinations.
  4. IIIVIIIVIIIVIIIVIII has $40,000$ combinations.

Rohan Lewis¶

2025.06.27¶

Code can be found here.