Created
March 18, 2018 17:57
-
-
Save chefnobody/cde788cd419f8b4cdf0139cc59bf3e0e to your computer and use it in GitHub Desktop.
Calculates the greatest common denominator of two numbers
This file contains 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 characters
import Foundation | |
func gcd(_ a:Int, _ b:Int) -> Int { | |
let r = a % b | |
if r != 0 { | |
return gcd(b, r) | |
} else { | |
return b | |
} | |
} | |
gcd(52, 39) | |
gcd(228, 36) | |
gcd(51357, 3819) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment