Created
May 21, 2014 13:40
-
-
Save larryfox/7f573afc0be4be74370d to your computer and use it in GitHub Desktop.
Luhn algorithm in Julia
This file contains hidden or 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 luhn | |
function luhn(value::String) | |
a = reverse(split(value, "")) | |
s = 0 | |
for i = 1:length(a) | |
n = parseint(a[i]) | |
isodd(i) || (n *= 2) | |
n < 10 || (n = sum(digits(n))) | |
s += n | |
end | |
s % 10 == 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment