Created
September 20, 2016 22:55
-
-
Save acegreen/d4733f4042be116da03a42a811ab6bfa to your computer and use it in GitHub Desktop.
Revisions
-
acegreen created this gist
Sep 20, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // Mark: - Factorial! // Iterative func factorialIterative(of number: Int) -> Int { var factorial: Int = 1 for i in 2...number { factorial *= i } return factorial } print("factorial Iterative", factorialIterative(of: 5)) // Recursive func factorialRecursive(of number: Int) -> Int { guard number > 1 else { return 1 } return number * factorialRecursive(of: number - 1) } print("factorial recursive", factorialRecursive(of: 5))