A gene is an ordered array of codons. Each codon contains three nucleotides, and each nucleotide is one of A, C, G, or T. section 2.1
A Swift representation builds the model in small layers:
- Represent a nucleotide with an enum whose cases are A, C, G, and T. section 2.1
- Represent a codon as a tuple of three Nucleotide values. section 2.1
- Define Gene as an array of codons, preserving their sequence order. section 2.1
- Add Comparable behavior to Nucleotide so codons and genes can support ordered searches. section 2.1
Converting a sequence into a gene
Given a nucleotide string, stringToGene() reads three characters at a time, converts them into a codon, and appends that codon to a Gene. If fewer than three nucleotides remain, it ignores the incomplete ending. A resulting gene can then be searched linearly or sorted before binary search. section 2.1
Figure 2.1. A nucleotide is represented by one of the letters A, C, G, and T. A codon is composed of three nucleotides, and a gene is composed of multiple codons.
Use the diagram to keep the representation hierarchy visible: nucleotide, codon, then gene. section 2.1




