Sha256: 5b8a87dfeea401af85b027d3177eb0bc6ec699ce6e20a0e87c00d05d338f373d

Contents?: true

Size: 378 Bytes

Versions: 200

Compression:

Stored size: 378 Bytes

Contents

function luhn(id::AbstractString)
    id = split(replace(id, ' ', ""), "")
    length(id) < 2 && return false
    all(all(isdigit, s) for s in 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

200 entries across 200 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.158 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.157 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.156 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.155 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.154 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.153 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.152 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.151 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.150 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.149 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.148 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.147 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.146 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.145 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.144 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.143 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.142 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.141 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.140 tracks/julia/exercises/luhn/example.jl