Jump to content

Run-length encoding: Difference between revisions

→‎{{header|Kotlin}}: (made example usable with https://github.com/dkandalov/rosettacode-kotlin)
(Kotlin implementation of Run Length Encoding)
(→‎{{header|Kotlin}}: (made example usable with https://github.com/dkandalov/rosettacode-kotlin))
Line 1,932:
=={{header|Kotlin}}==
Tail recursive implementation of Run Length Encoding
<lang scala>tailrec fun runLengthEncoding(text:String,prev:String=""):String {
<lang scala>
if (text.length == 0isEmpty()){
tailrec fun runLengthEncoding(text:String,prev:String=""):String {
if (text.length == 0){
return prev
}
Line 1,941 ⟶ 1,940:
return runLengthEncoding(text.substring(count),prev + "$count$initialChar" )
}
</lang>
 
fun main(args: Array<String>) {
Tests:
<lang scala>
assert(runLengthEncoding("TTESSST") == "2T1E3S1T")
assert(runLengthEncoding("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW")
== "12W1B12W3B24W1B14W")
}</lang>
 
=={{header|Lasso}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.