Created
February 13, 2017 08:28
-
-
Save LeebDeveloper/35424a6008ecdfc602a88b78130bc896 to your computer and use it in GitHub Desktop.
Luhn checksum check with Erlang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(luhn). | |
-export([check/1]). | |
-spec check([integer()]) -> boolean(). | |
check(Number) -> | |
{Check, _} = lists:foldr( | |
fun | |
(N, {A, odd}) -> | |
{A + N, even}; | |
(N, {A, even}) -> | |
N1 = case N * 2 of | |
Big when Big > 9 -> Big - 9; | |
Small -> Small | |
end, | |
{A + N1, odd} | |
end, {0, odd}, Number), | |
(Check rem 10) == 0. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment