Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Hamming Distance Between 2 Strings - Fast(est) Way?

by wazoox (Prior)
on Oct 14, 2005 at 15:34 UTC ( [id://500263]=note: print w/replies, xml ) Need Help??


in reply to Hamming Distance Between 2 Strings - Fast(est) Way?

Depending upon your data, simply checking first that the strings don't match can make it much faster :

sub hd1 { #String length is assumed to be equal my ($k,$l) = @_; # next line added return 0 if $k eq $l; my $len = length ($k); my $num_mismatch = 0; for (my $i=0; $i<$len; $i++) { ++$num_mismatch if substr($k, $i, 1) ne substr($l, $i, 1); } return $num_mismatch; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://500263]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-04-16 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found