Algorithms in Swift