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.119 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.118 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.117 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.116 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.115 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.114 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.113 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.111 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.110 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.109 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.108 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.107 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.106 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.105 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.104 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.103 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.102 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.101 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.100 tracks/julia/exercises/luhn/example.jl
trackler-2.2.1.99 tracks/julia/exercises/luhn/example.jl