Improving a slow solution for Longest Collatz Sequence

@sasajuric Thanks so much for the answer, the detailed explanation and tricks. I suspected Elixir would be slow, but not so much slower than Ruby. That was my main concern: the Elixir version was as naive as Ruby’s (same algorithm), but the results were so different :slight_smile: Your explanations about that make a lot of sense.

By “problem”, I did not want to imply it in the general sense, but just the comparison between Collatz implementations, which as you mentioned, are not representative of anything important. It was just out of raw curiosity. My co-worker did this problem in Fortran, and got less than 10 milliseconds as a result!

The process dictionary and Bitwise module are really great tricks, and I’ll take your word to not use them in production. And seems that I did not consider the VM’s warm-up, ha!

1 Like