Run-length encoding, RLE in short, is replacing repeated patterns in a text by the number of repetitions plus the pattern that is repeated. This way, a text that contains many repetitions can be saved under a strongly shortened form. For this assignment we will keep it at the simple form of run-length encoding that applies the following rules:
Every sequence of 2 to 9 consecutive identical characters are coded by two characters. The first character is a digit that indicates the length of the sequence. The second character is the repeated character itself. A sequence of more than 9 consecutive identical characters is treated by coding the first 9 characters and afterwards coding the rest.
A sequence of characters that doesn't contain any consecutive identical characters are coded by the digit 1, followed by the sequence of characters and again closed with 1. If the digit 1 occurs in the sequence, this digit is doubled.
Write a function rle to which a string $$s$$ should be given as an argument. The function must print the coded form of the string $$s$$ as a result. This result is obtained by application of the simple run-length encoding scheme that was described in the introduction.
>>> rle('AAAAAABCCCC')
'6A1B14C'
>>> rle('12344')
'11123124'