Sha256: 5127770762e9a677140a4999695a318fc724c167afe94bc46cf4f6c2590a7d53

Contents?: true

Size: 517 Bytes

Versions: 127

Compression:

Stored size: 517 Bytes

Contents

function encode(s)
    (length(s) == 0) && (return s)

    count = 0
    for char in s
        (char == s[1]) ? (count += 1) : break
    end
    count_str = (count == 1) ? "" : dec(count)
    return string(count_str, s[1], encode(s[count + 1 : end]))
end



function decode(s)
    function expand(count_str, char)
        count = (count_str == "") ? 1 : parse(Int, count_str)
        return char ^ count
    end

    result = ""
    return string((expand(rm.captures...) for rm in eachmatch(r"(\d*)(\D)", s))...)
end

Version data entries

127 entries across 127 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.97 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.96 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.95 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.94 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.93 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.92 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.91 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.90 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.89 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.88 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.87 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.86 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.85 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.84 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.83 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.82 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.81 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.80 tracks/julia/exercises/run-length-encoding/example.jl
trackler-2.2.1.79 tracks/julia/exercises/run-length-encoding/example.jl