Sha256: 3554420c26744195521b040de5b530ccf727ba38fad9ff356af831d6e7b36936
Contents?: true
Size: 362 Bytes
Versions: 106
Compression:
Stored size: 362 Bytes
Contents
function luhn(id::AbstractString) id = split(replace(id, ' ', ""), "") length(id) < 2 && return false all(isdigit, id) || return false numbers = Int[] for val in id push!(numbers, parse(Int, val)) end for i in length(numbers) - 1:-2:1 numbers[i] = (numbers[i] * 2) % 9 end return sum(numbers) % 10 == 0 end
Version data entries
106 entries across 106 versions & 1 rubygems