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

Version Path
trackler-2.0.8.22 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.21 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.20 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.19 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.18 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.17 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.16 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.15 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.14 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.13 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.12 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.11 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.10 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.9 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.8 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.7 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.6 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.5 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.4 tracks/java/exercises/hamming/src/example/java/Hamming.java
trackler-2.0.8.3 tracks/java/exercises/hamming/src/example/java/Hamming.java