PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'''
run-length encoding for Python
coded by Marco Abrate 2017
challenge by noobcoder
Challenge: File compression and "run-length encoding"
This challenge is meant to explore the basic idea behind file compression using a very naive type of compression called "run-length encoding".
The idea behind run-length encoding is to take a string and replace
all repeated sequences of characters with the number of times that character is repeated followed by that character.
For example, we'd encode the string:
WWWWWWAAAAAAWWWWWWAAAAAABBBBBB
as:
6W6A6W6A6B
As you can see, this "encoded" string is actually *shorter* than the input
string but still contains all the information we need to reconstruct the
original.
On the other hand, the string "ABCEDFG" would be encoded as:
1A1B1C1D1E1F1G
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run