Created
December 14, 2015 20:15
-
-
Save eam/c25e8c95d37de848d724 to your computer and use it in GitHub Desktop.
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
| #!/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