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.0.8.15 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.14 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.13 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.12 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.11 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.10 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.9 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.8 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.7 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.6 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.5 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.4 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.3 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.2 tracks/julia/exercises/luhn/example.jl
trackler-2.0.8.1 tracks/julia/exercises/luhn/example.jl
trackler-2.0.7.0 tracks/julia/exercises/luhn/example.jl
trackler-2.0.6.44 tracks/julia/exercises/luhn/example.jl
trackler-2.0.6.43 tracks/julia/exercises/luhn/example.jl
trackler-2.0.6.42 tracks/julia/exercises/luhn/example.jl
trackler-2.0.6.41 tracks/julia/exercises/luhn/example.jl