# Sunday Times Teaser 3105 – Roman Primes

*by Peter Good*

#### Published Sunday March 27 2022 (link)

Romulus played a game using several [1] identical six-sided dice. Each die face shows a different single-character Roman numeral. He rolled two dice and was able to form a prime number in Roman numerals by arranging the two characters. Romulus rolled more dice and, after each roll, formed a prime number with one more character, rearranging the sequence as needed, until he could no longer form a prime number less than 100. He was using standard notation where a character before another that is 5 or 10 times larger is subtracted from the larger one, eg, IX=9.

After playing many games he realised that there were exactly three primes less than 100 that could not occur in any of the sequences.

In decimal notation and in ascending order, what were those prime numbers?

[1] The word ‘several’ here is not intended to impose or imply any limit on the number of available dice.

Without the clarification in red, this teaser has multiple solutions which this solution provides

It runs in 7 milliseconds (profile timing).

But I see that Jim Randell has found a different scenario not involving C.

I noticed this too. I have now modified my program accordingly and this shows that the symbols I, V, X and L have to be present and are combined with any of the three pairs from (C, D, M). Sadly this results in two different teaser answers.

Hi John,

Your answer agrees with the answer that my original code produced but after an email exchange with John Owen, who co-ordinates the teasers for the Sunday Times, I now know that this is not the solution that Peter Good intended. I have hence revised my code and added a clarification to the teaser text.

Erling has also now updated his solution and, since this makes many earlier comments appear very odd, I have decided to delete them (this includes one of your comments – my apologies).

If you want to update your solution, I will happily substitute a revised version if you email it to me.

(“Who Wants Yesterday’s Teaser”, Mick Jagger, attr.)

I noticed that my code was doing a lot of ‘wheel spin’. This revised version cuts down on that and is faster and more elegant.

I like your version so I have produced my version of your code (and improved the speed from 4 milliseconds to 2 milliseconds).

A slightly different approach with elements from our ‘combined code’ using recursion without ‘yield’. This should be even faster.

As a challenge, I decided to rewrite lines 32 – 35 of your version of my version as a list comprehension. It works but it’s not pretty. A bit of contortion was required upstream of the comprehension to avoid a Runtime error.