diff --git a/GCD/GCD.playground/Contents.swift b/GCD/GCD.playground/Contents.swift index bb8d49055..7da3ccc26 100644 --- a/GCD/GCD.playground/Contents.swift +++ b/GCD/GCD.playground/Contents.swift @@ -16,6 +16,7 @@ gcd(841, 299, using: gcdBinaryRecursiveStein) // 1 do { try lcm(2, 3) // 6 try lcm(10, 8, using: gcdRecursiveEuklid) // 40 + try lcm(3, 4) // 12 } catch { dump(error) } diff --git a/GCD/GCD.playground/Sources/GCD.swift b/GCD/GCD.playground/Sources/GCD.swift index 4eb0c7621..fffbfc7b2 100644 --- a/GCD/GCD.playground/Sources/GCD.swift +++ b/GCD/GCD.playground/Sources/GCD.swift @@ -121,7 +121,7 @@ func findEasySolution(_ m: Int, _ n: Int) -> Int? { public enum LCMError: Error { - case divisionByZero + case nonPositive } /* @@ -132,12 +132,12 @@ public enum LCMError: Error { - Parameter using: The used gcd algorithm to calculate the lcm. If nothing provided, the Iterative Euclidean algorithm is used. - - Throws: Can throw a `divisionByZero` error if one of the given + - Throws: Can throw a `nonPositive` error if one or both of the given attributes turns out to be zero or less. - Returns: The least common multiplier of the two attributes as - an unsigned integer + a signed integer */ public func lcm(_ m: Int, _ n: Int, using gcdAlgorithm: (Int, Int) -> (Int) = gcdIterativeEuklid) throws -> Int { - guard m & n != 0 else { throw LCMError.divisionByZero } + guard m > 0, n > 0 else { throw LCMError.nonPositive } return m / gcdAlgorithm(m, n) * n }