Created
April 11, 2016 04:35
-
-
Save pulkit21/aa856a1f9d7502e44bf55083494c89f3 to your computer and use it in GitHub Desktop.
Run length encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_encode(string) | |
print string.chars.chunk{|i| i}.map{|k, a| a.length == 1 ? k : k + a.length.to_s }.join | |
end | |
INPUT STRING | |
aaaaabbbbbbbbbccccpqrstuv | |
OUTPUT | |
a5b9c4pqrstuv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment