Skip to content

Instantly share code, notes, and snippets.

@LeebDeveloper
Created February 13, 2017 08:28
Show Gist options
  • Save LeebDeveloper/35424a6008ecdfc602a88b78130bc896 to your computer and use it in GitHub Desktop.
Save LeebDeveloper/35424a6008ecdfc602a88b78130bc896 to your computer and use it in GitHub Desktop.
Luhn checksum check with Erlang
-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