Compressing a program in plain text

I came across this neat way of sharing a program in limited space in plain text (Stack Overflow comments are limited in length).

require 'base64';require 'zlib';puts Zlib.inflate(Base64.decode64("eJxlkMEOwiAQRO98hekFuGzxQEwPXvwR01ZqiYHqBk2Tln8XDlWgnDbM25nJonq9NaoD7ZTtR9PigxK09zM7AkgRHieXTYHOsBNf1nklM6B6TuhYpdp+rPgSdiCOi/d/kQ71QBOtAVFLEDly05+UYQ2H+MckL6z0zioDdJG1S9K1K4iQAW66DhnmiqRYKEJFXMByux+XuOJ2XdO60dKsjC7aBtyTL5O5hLk="))

When run this produces:

require 'benchmark'
rng=(1..50000)
Benchmark.bm(7){|x|
x.report("each"){rng.each{}}
x.report('f/f'){rng.each{9.0/5.0}}
x.report('fdiv'){rng.each{(9).fdiv(5)}}
x.report('f/i'){rng.each{9.0/5}}
x.report('i/f'){rng.each{9/5.0}}
x.report('i/tf'){rng.each{9/(5).to_f}}
x.report('tf/i'){rng.each{(9).to_f/5}}
x.report('tf/tf'){rng.each{(9).to_f/(5).to_f}}
require 'mathn'
x.report('i/i'){rng.each{9/5}}
}

Source: Stack Overflow

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.