Skip to content

Instantly share code, notes, and snippets.

@kamilhism
Created October 19, 2012 18:29
Show Gist options
  • Save kamilhism/3919832 to your computer and use it in GitHub Desktop.
Save kamilhism/3919832 to your computer and use it in GitHub Desktop.
test task solve
str = "111222333" * 1000000
a = Time.now
str.scan(/(0+|1+|2+|3+|4+|5+|6+|7+|8+|9+)/).map { |i| "#{i[0].size}#{i[0][0]}" }.join
puts Time.now - a
a = Time.now
str.scan(/((\d)\2*)/).map { |i| "#{i[0].size}#{i[1]}"}.join
puts Time.now - a
a = Time.now
str.scan(/(\d)(\1*)/).map { |i| "#{i[1].size + 1}#{i[0]}" }.join
puts Time.now - a
#4.170684232
#3.517496366
#3.928271342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment