Came across this on the “Programming Praxis” blog

I thought I’d use something other than a “typical” programming language, by which I mean not “an esoteric language”, but rather something that’s not thought of as a programming language: Mathematica.

This is the entirety of the solution, a one-liner that (using Timing), also shows how long it took.

The above is an image, but an online (read-only) notebook containing this evaluation is here at Wolfram Cloud.

Ten years ago, I’d be on the side of the fence saying “but that’s cheating“, or “hey, that’s not really programming“, but today my attitude is more of “use the right tool for the job“.

And Mathematica is a mighty fine tool !!