Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in constructor of Gene class -- Listing 2.4 on page 29 #11

Open
samkramer opened this issue Apr 3, 2024 · 0 comments
Open

Error in constructor of Gene class -- Listing 2.4 on page 29 #11

samkramer opened this issue Apr 3, 2024 · 0 comments

Comments

@samkramer
Copy link

samkramer commented Apr 3, 2024

Listing 2.4 on page 29:

// BUG: this code contains an error -- fails to read last three characters of string
for (int i = 0; i < geneStr.length() - 3; i += 3) {
    codons.add(new Codon(geneStr.substring(i, i + 3)));
}
// Here is an example of a corrected version:
final int len = geneStr.length();
final int partitionSize = 3;
for (int i = 0; i < len; i += partitionSize) {
    codons.add(new Codon(geneStr.substring(i, Math.min(len, i + partitionSize))));
}
// Test case that fails with original implementation
Codon ttt = new Codon("TTT");
System.out.println(myGene.linearContains(ttt)); // true
System.out.println(myGene.binaryContains(ttt)); // true

Note: I would recommend to only update this code on GitHub, as clearly this is being used to read in sample input data for the algorithm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant