Created
September 11, 2016 07:31
-
-
Save danielpowell4/9de823c66e8829fcffaa5fa4e259f8fb to your computer and use it in GitHub Desktop.
Given the lengths of two different tracks, output how many laps it will take until two joggers meet again
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
# lcm => least common multiple | |
# one-liner | |
def nbr_of_laps(x,y) | |
[x.lcm(y)/x, x.lcm(y)/y] | |
end | |
# simple | |
def nbr_of_laps(x, y) | |
lcm = x.lcm(y) | |
[lcm/x, lcm/y] | |
end | |
# alt | |
def nbr_of_laps(x,y) | |
l = [x,y].reduce(:lcm) | |
[l/x,l/y] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment