Skip to content

Instantly share code, notes, and snippets.

@eam
Created December 14, 2015 20:15
Show Gist options
  • Select an option

  • Save eam/c25e8c95d37de848d724 to your computer and use it in GitHub Desktop.

Select an option

Save eam/c25e8c95d37de848d724 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
num, iters = ARGV
def encode_string s
s.gsub(/(0+|1+|2+|3+|4+|5+|6+|7+|8+|9+)/) { |m| l = m.length; "#{m.length}#{m[0]}" }
end
puts "encoding #{num} with #{iters} iterations"
iters.to_i.times do |i|
start = Time.now.to_f
num = encode_string num
puts "#{i}: #{num.length} runtime: #{Time.now.to_f - start}"
end
#puts "got: #{num} with length #{num.length}"
puts "length #{num.length}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment