Susan Harkins (397) [Avatar] Offline
#1
Please post errors found in the published version of Classic Computer Science Problems in Swift here. If necessary, we'll publish a comprehensive list for everyone's convenience. Thanks!

Susan Harkins
Errata Editor
Manning Publications
568224 (4) [Avatar] Offline
#2
Page 109, func mutate() has a bug.
The first half of the if statement is nonsense, it makes no sense to insert a random letter and kill another. You end up with useless Chromosomes.
replace entire statement (5 lines) by the 4th line only. I've made other cosmetic changes to arrive at:

    public func mutate() {
        let position1 = Int(arc4random_uniform(UInt32(genes.count)))
        var position2: Int
        repeat {
            position2 = Int(arc4random_uniform(UInt32(genes.count)))
        } while position1 == position2
        genes.swapAt(position1, position2)
    }

David Kopec (8) [Avatar] Offline
#3
Thanks for the suggestion!