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

Version Path
trackler-2.1.0.41 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.40 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.39 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.38 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.37 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.36 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.34 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.33 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.32 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.31 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.30 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.29 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.28 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.27 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.26 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.25 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.24 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.23 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.22 tracks/julia/exercises/luhn/example.jl
trackler-2.1.0.21 tracks/julia/exercises/luhn/example.jl