Skip to content

Error in Least Common Multiple algorithm #943

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
gkwaerp opened this issue Aug 24, 2020 · 0 comments
Open

Error in Least Common Multiple algorithm #943

gkwaerp opened this issue Aug 24, 2020 · 0 comments

Comments

@gkwaerp
Copy link

gkwaerp commented Aug 24, 2020

Brief Intro

https://github.com/raywenderlich/swift-algorithm-club/tree/master/GCD
The code fails (fatalError) in various valid scenarios, e.g. lcm(3, 4) --> should be 12.

More Details

guard (m & n) != 0 else { throw LCMError.divisionByZero }

This is not a division by zero check, nor is it a relevant check for this algorithm.
Would recommend changing to e.g.

guard m > 0, n > 0 else { throw LCMError.nonPositiveNumbers } //Must be added to LCMError.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant