Luhn algorithm in Elixir: implementation, refactoring, and benchmarking
Some time ago, I have encountered a programming exercise in which the goal was to implement Luhn algorithm for credit card number validation. At first I implemented the algorithm in Ruby and then decided to implement it in Elixir. Eventually, I like how Elixir version looks like.
In this article Elixir 1.2.2 is being used.
Initial version It is assumed that credit card numbers are being read from a file and that check digit is included in a credit card number.
The Luhn algorithm is quite straightforward. Description from Wikipedia 1:
The formula verifies a number against its included check digit, which is usually appended to a partial account number to generate the full account number.