Encode/compress sequence of repeating integers
Posted
by Alex
on Stack Overflow
See other posts from Stack Overflow
or by Alex
Published on 2010-04-02T13:05:33Z
Indexed on
2010/04/02
13:13 UTC
Read the original article
Hit count: 312
Hey there!
I have very long integer sequences that look like this (arbitrary length!):
0000000001110002220033333
Now I need some algorithm to convert this string into something compressed like
a9b3a3c3a2d5
Which means "a 9 times, then b 3 times, then a 3 times" and so on, where "a" stands for 0, "b" for 1, "c" for 2 and "d" for 3.
How would you do that? So far nothing suitable came to my mind, and I had no luck with google because I didn't really know what to search for. What is this kind of encoding / compression called?
PS: I am going to do the encoding with PHP, and the decoding in JavaScript.
© Stack Overflow or respective owner