I was adding my Ruby and Nim code for the Miller-Rabin Primality Test to Rosetta Code and noticed there was no example for Crystal. In fact, there no Crystal examples for a lot of the code categories.
So here’s my Crystal version of Miller-Rabin, which is almost a 100% exact translation of the Ruby version. I’ve also included the Nim version for comparison (Nim is compiled).
As an aside, I notice there is no syntax highlighting for the Crystal code as there is for Ruby.
The Ruby version is much faster because it has a fast BigInt implementation.
I think it would be a good exercise for people looking to do something tangible with Crystal, and get their feet wet with it, to implement any of the missing categories, to add them to the list. This will surely benefit Crystal, by being more visible for more categories, and acting as coding tutorials too. An easy way to jump into this is to just translate the Ruby versions into Crystal as a start.