Here it is in JavaScript (feel free to play around with it): <a href="https://tonicdev.com/tolmasky/widest-roman-prime" rel="nofollow">https://tonicdev.com/tolmasky/widest-roman-prime</a><p>Took me only a couple of minutes since it was mainly just searching for the right npm packages to piece together. Say what you like about micro libraries, but for explorations like this it really makes JavaScript in a league of its own.
Should have just done it in Common Lisp. Roman numeral formatting is built-in.<p><pre><code> ? (format nil "~@r" 3989)
"MMMCMLXXXIX"</code></pre>
The problem is underspecified because it does not define under which renderer the text should be measured. Kerning could reorder some of the close ties.
Strictly speaking that's the widest modern usage Roman prime under 4000.<p>The actual Romans were inconsistent in their use of the subtractive principle, see <a href="http://www.straightdope.com/columns/read/1371/what-is-the-proper-way-to-style-roman-numerals-for-the-1990s" rel="nofollow">http://www.straightdope.com/columns/read/1371/what-is-the-pr...</a><p>So there might be ways to construct a wider one.
Its funny with all these new sort of bracket like functional programming languages with similar syntax it actually took me a minute to figure out that the code is Swift(probably lack of experience)... Looks like Scala.. no scala doesn't use let.. is it Rust.. nope not Rust.. rust does not use "import".. can't be Ocaml or F# because of no brackets... ah UIKit.
The next question that popped into my head is, what's the thinnest Roman Prime?<p>Took me about sixty seconds before I realized that was a stupid question :)
The challenge wasn't print the largest prime under 4000, it was find the prime with the most digits. So the lisper example gave the wrong answer. Still need to generate the prime, count the digits and return the one with the most digits. No sure that the lisp version would be less lines of code, but I'll guess a recursive version would be close