A codon is a sequence of three nucleotides. Each nucleotide is represented by A, C, G, or T, and each codon specifies an amino acid; multiple amino acids can form a protein. section 2.1
In Swift, represent a codon as a three-element tuple and a gene as an array of codons. A parser reads a nucleotide string in groups of three and ignores a final incomplete group. section 2.1
Representing and parsing codons
typealias Codon = (Nucleotide, Nucleotide, Nucleotide) typealias Gene = [Codon] func stringToGene(_ s: String) -> Gene { var gene = Gene() for i in stride(from: 0, to: s.count, by: 3) { guard i + 2 < s.count else { return gene } // Convert the next three characters into a Codon. } return gene } let acg: Codon = (.A, .C, .G) 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.
Shows the relationship between a nucleotide, a codon composed of three nucleotides, and a gene composed of multiple codons. section 2.1
