This is a solution for the problem named Codes on the kattis platform:
Given a generator matrix of a linear code, calculate the minimum distance of the code.
I'm looking for reviews on optimization and best practices. Code readability should be preserved.
public static class LinearCode {
private int[][] generator;
private int n;
private int k;
public LinearCode(int[][] generator, int n, int k) {
this.generator = generator;
this.n = n;
this.k = k;
}
public int getMinimumDistance() {
int minDistance = n;
int maxKString = 1 << k;
// generate all k-strings
for (int i = 1; i < maxKString; i++) {
int kstring = i;
int distance = 0;
// matrix multiplication
for (int j = 0; j < n; j++) {
int p = 0;
for (int z = 0; z < k; z++) {
int a = generator[j][k-z-1];
int b = (kstring >>> z) & 1;
p = (p + a * b) & 1;
}
// distance as number if 1 bits
distance += p;
}
minDistance = Math.min(minDistance, distance);
}
return minDistance;
}
}