Created
April 16, 2016 21:52
-
-
Save lrechert/d4c535e4da97ddba445431ad00ae468c to your computer and use it in GitHub Desktop.
Ruby Challenge - Two Joggers
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 characters
# Description | |
# Bob and Charles are meeting for their weekly jogging tour. They both start | |
# at the same spot called "Start" and they each run a different lap, which | |
# may (or may not) vary in length. Since they know each other for a long time | |
# already, they both run at the exact same speed. | |
# Task | |
# Your job is to complete the function nbrOfLaps(x, y) that, given the length | |
# of the laps for Bob and Charles, finds the number of laps that each jogger | |
# has to complete before they meet each other again, at the same time, at the start. | |
# The function takes two arguments: | |
# The length of Bob's lap (larger than 0) | |
# The length of Charles' lap (larger than 0) | |
# The function should return an array containing exactly two numbers: | |
# The first number is the number of laps that Bob has to run | |
# The second number is the number of laps that Charles has to run | |
def nbr_of_laps(x, y) | |
lcm = [x,y].reduce(:lcm) | |
[lcm/x,lcm/y] | |
end |
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 characters
require_relative '../two_joggers.rb' | |
describe 'two joggers' do | |
it 'returns the correct number of laps per jogger' do | |
expect(nbr_of_laps(3, 5)).to eql [5, 3] | |
end | |
it 'returns the correct number of laps per jogger' do | |
expect(nbr_of_laps(4, 6)).to eql [3, 2] | |
end | |
it 'returns the correct number of laps per jogger' do | |
expect(nbr_of_laps(5, 5)).to eql [1,1] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment