I like this solution the most. Some questions on @wacnt (like this one) can't be answered because Wolfram Alpha's NLP fails to recognize the algorithm implicit in the question, but if it was able to translate the problem statement into a machine-readable form, this would be very close to it.
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.
> Say what you like about micro libraries, but for explorations like this it really makes JavaScript in a league of its own.Say what you like about micro libraries, but for explorations like this it really makes JavaScript in a league of its own.
Indeed, we spend so much time arguing about programming languages, when in reality the presence or absence of libraries is much more important.
Since most proportional fonts have somewhat similar widths, probably not. But if you just look at the longest string (or use a non-proportional font) there will be four roman numbers of equal length/width.
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.
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.
So it seems but mostly because of the UI component where you can calculate the width of the resulting text without having to hardcode the width of individual characters.
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
It's not to find the one with the most digits. It's to find the widest one in Times New Roman. Times New Roman is not a fixed-width font, so the widest one might have less digits than some other one. For example I is less wide than M.