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.78 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.77 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.76 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.75 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.74 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.73 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.72 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.71 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.70 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.69 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.68 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.67 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.66 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.65 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.64 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.63 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.62 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.61 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.60 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.59 tracks/julia/exercises/luhn/example.jl