Refactor problem 1 in Swift to use functional style
Solve problem 2 in Swift