M
Martin Hansen
What is the fastest way to calculate the Hamming Distance between two
equally long strings in Ruby? A have looked at the amatch gem, but I was
wondering what can be done with Ruby only?
Here is a very interesting discussion on the subject:
http://www.perlmonks.org/?node_id=500235
Note the elegant and extremely fast Perl solution:
sub hd {
return ($_[0] ^ $_[1]) =~ tr/\001-\255//;
}
Cheers,
Martin
equally long strings in Ruby? A have looked at the amatch gem, but I was
wondering what can be done with Ruby only?
Here is a very interesting discussion on the subject:
http://www.perlmonks.org/?node_id=500235
Note the elegant and extremely fast Perl solution:
sub hd {
return ($_[0] ^ $_[1]) =~ tr/\001-\255//;
}
Cheers,
Martin