Add Swift version of Problem 23