+ 8

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 More info: http://en.wikipedia.org/wiki/Run-length_encoding * Make a program in any language(s) you want, to encode a string using run-length encoding. * Bonus: Make a decoder, also.

7th Oct 2017, 7:41 AM
noobcøder
noobcøder - avatar
8 Answers
7th Oct 2017, 8:21 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 7
I wrote a second version to solve a problem you can have in this challenge: when encoding a string containing numbers you can have a decoding error (if you want to write a decoder..). for example if you encode '11111111111222222222222' you get '111122', but decoding '111122' you get '1122' that is different from the initial string. My second version introduces a new symbol ('.', but you can change it if you want) to separate the counter from the counted numbers so that if you encode '11111111111222222222222' you get '11.112.2' and the decoder can read "there are eleven 1's and twelve 2's" and give you back the right string... try it! 🐍 https://code.sololearn.com/cbBX8YFIqykh/?ref=app
7th Oct 2017, 10:00 PM
m abrate
m abrate - avatar
7th Oct 2017, 8:15 PM
m abrate
m abrate - avatar
+ 4
https://code.sololearn.com/cqmDOpiuIGPI/?ref=app
7th Oct 2017, 12:38 PM
Kartikey Sahu
Kartikey Sahu - avatar
7th Oct 2017, 10:47 AM
Amr Ibrahim Khudair
Amr Ibrahim Khudair - avatar
+ 3
https://code.sololearn.com/cID50SHkvGo5/?ref=app
7th Oct 2017, 10:47 AM
Louis
Louis - avatar
+ 2
my practice on python https://code.sololearn.com/cOU95o2TsnSs/?ref=app example, input: aaabbc:encode result: 3a2b1c and input: 3a2b1c:decode output: aaabbc
7th Oct 2017, 11:43 AM
ysraelcon
ysraelcon - avatar
+ 2
Dude, this one was really hard, follow my answer. https://code.sololearn.com/coHIa7tHW6Qx/#py
9th Oct 2017, 3:23 PM
Pedro Moresco
Pedro Moresco - avatar