Initially I had forgotten to delete the ets tables so my lappy started grinding after a few iterations as it thrashed the swap. Ah the joys of learning a feature via the API reference…

One nagging question I had was the speed of using the lists:seq and the list comprehension. So I swapped to an explicit loop via parameter matching, which ran slightly faster. Luckily I realised the code smell: the original could be mapped across many processors with little effort, but the latter was hard coded looping.

It is a little bit of a cheat doing it in Erlang, as the major point of the original problem is knowing the limits of your data types, and thus C’s int type is not large enough to manage the problem. I am not even sure is a int64 is large enough or if you need to drop down to your own large number type. Ether way, Erlang does not suffer from this problem with it’s dynamic size number type.

The problem states that numbers up to 1,000,000 are known to converge to 1, so I ran the problem from 1 -> 1,000,000 and the largest number of steps is 525. This took around 10 seconds on my MacBook which I feel is performant enough.

I quite like using the lists:seq generator and the list comprehension together, but I wonder if there is a better way to-do number generation and function calling in a single line.