Run Length Encoding

Run Length Encoding is a method of data compression which involves reducing the length of the encoded data by replacing repeated elements in the data sequence with a shorter representation in order to save space.

To give you an example, quoted directly from the January 2015 issue of OpenSource as a coding problem,

“You are given an input string and asked to write a code snippet to return the run length encoded representation of that string. For example, if you are given the string aaaccefhhh, your function should return the string a3c2e1f1h3.”

Notice that the numbers after each alphabet in the output string denote the number of repeated alphabets in the input string sequence. This is Run Length Encoding.

I decided to write this program after a friend challenged me to see if I had the testicular fortitude at coding.

I think it’s fair to say I proved my point. Here’s the program, and it’s free to use for whatever purpose you might have in mind, all I ask for is credit to the original author if the situation permits it: