Skip to content

Instantly share code, notes, and snippets.

@larryfox
Created May 21, 2014 13:40
Show Gist options
  • Save larryfox/7f573afc0be4be74370d to your computer and use it in GitHub Desktop.
Save larryfox/7f573afc0be4be74370d to your computer and use it in GitHub Desktop.
Luhn algorithm in Julia
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