Course of Raku / Addendum 🆕 / Working with data / Text and strings / Exercises

Run-length encoding

Problem

Compress the string aaabbbbcc by replacing each run of identical letters with the letter followed by the length of the run, giving a3b4c2. Print the compressed string.

Example

The program prints:

a3b4c2

Solution

See the solution

Course navigation

Solution: Caesar cipher   |   Solution: Run-length encoding