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/ruby -w | |
require 'set' | |
Entry = Struct.new :id, :instance do | |
def self.parse(line) | |
if /ID=\s*'([^']*)'\s+INSTANCE=\s*'([^']*)'/ =~ line | |
new $1, $2 | |
else | |
raise "Cannot parse: %p" % line | |
end |
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
def dameraulevenshtein(seq1, seq2) | |
len1 = seq1.length | |
len2 = seq2.length | |
oneago = nil | |
row = (1..len2).to_a << 0 | |
len1.times do |i| | |
twoago, oneago, row = oneago, row, Array.new(len2) {0} << (i + 1) | |
len2.times do |j| | |
cost = seq1[i] == seq2[j] ? 0 : 1 | |
delcost = oneago[j] + 1 |