I noticed an ad for Super Bowl XLVI on a pizza box this morning. The Roman numeral XLVI does not repeat any character. This brought up a couple questions.
- How many Roman numerals are possible if you’re not allowed to repeat a character?
- Could you write a (reasonably short) regular expression to find all such numbers?
You can post your solutions to either question in the comments.
There has never been universal agreement on the rules for constructing Roman numerals, so your solution would depend on your choice of rules. For our purposes here, assume the valid characters are I, V, X, L, C, D, and M. Also, assume any character can be subtracted from a larger character. For example, you can assume IL is a valid representation of 49.
For a more challenging problem, you can use the more restrictive subtraction rules.
- I can be subtracted from V and X only.
- X can be subtracted from L and C only.
- C can be subtracted from D and M only.
- V, L, and D can never be subtracted.
Other puzzle posts: