in reply to The sum of absolute differences in the counts of chars in two strings.
print diffCount('aaaaacaacaaagcc', 'acaggtgacaaaaaa'); sub diffCount { my (%counts, $sum, $i); $counts{substr($_[0], $_, 1)}++ for 0..(length($_[0]) - 1); $counts{substr($_[1], $_, 1)}-- for 0..(length($_[1]) - 1); $sum += abs $_ for values %counts; return $sum; }
I tried other methods using split, regex, etc., but this benchmarked the fastest. Obviously, doing the same thing in C or C++ would be even faster.
|
|---|