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