Created
January 6, 2015 02:07
-
-
Save chadbrewbaker/7fd89e87c040cd5977a7 to your computer and use it in GitHub Desktop.
Computes information distance between two files
This file contains 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
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