Anonymous user
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 {▼
▲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" )
}
fun main(args: Array<String>) {
assert(runLengthEncoding("TTESSST") == "2T1E3S1T")
assert(runLengthEncoding("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW")
== "12W1B12W3B24W1B14W")
}</lang>
=={{header|Lasso}}==
|