Skip to content

Instantly share code, notes, and snippets.

@antonfefilov
Last active December 18, 2015 14:19
Show Gist options
  • Save antonfefilov/5796238 to your computer and use it in GitHub Desktop.
Save antonfefilov/5796238 to your computer and use it in GitHub Desktop.
Как то так ...
old_string = "312211"
counter = 1
new_string = ""
for index_of_char in 0..old_string.size-1
char = old_string[index_of_char]
if old_string[index_of_char] == old_string[index_of_char+1]
counter += 1
next
else
new_string << counter.to_s
new_string << char.to_s
counter = 1
end
end
puts new_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment