Sha256: 584220ae3146de1bb798119039fad3229639121f5995369bc5e814655b8830cd
Contents?: true
Size: 713 Bytes
Versions: 123
Compression:
Stored size: 713 Bytes
Contents
public class Hamming { public static int compute(String leftStrand, String rightStrand) { if(leftStrand.length() != rightStrand.length()) { throw new IllegalArgumentException("leftStrand and rightStrand must be of equal length."); } final int length = Math.min(leftStrand.length(), rightStrand.length()); int distance = 0; for (int i = 0; i < length; i++) { distance += hammingContributionAt(i, leftStrand, rightStrand); } return distance; } private static int hammingContributionAt(int index, String leftStrand, String rightStrand) { return leftStrand.charAt(index) != rightStrand.charAt(index) ? 1 : 0; } }
Version data entries
123 entries across 123 versions & 1 rubygems