Skip to content

Instantly share code, notes, and snippets.

@chadbrewbaker
Created January 6, 2015 02:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadbrewbaker/7fd89e87c040cd5977a7 to your computer and use it in GitHub Desktop.
Save chadbrewbaker/7fd89e87c040cd5977a7 to your computer and use it in GitHub Desktop.
Computes information distance between two files
require "zlib"
if(ARGV.length != 2)
puts "usage: ruby zdist.rb file1 file2"
else
f1 = File.read(ARGV[0])
f2 = File.read(ARGV[1])
f1d = Zlib::Deflate.deflate(f1)
f2d = Zlib::Deflate.deflate(f2)
compressed = Zlib::Deflate.deflate(f1+f2)
puts (compressed.length - [f1d.length, f2d.length].min).to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment