-
-
Save RickArora/16fb844c8744ead5e8efc18a9900da73 to your computer and use it in GitHub Desktop.
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
# Write a method, coprime?(num_1, num_2), that accepts two numbers as args. | |
# The method should return true if the only common divisor between the two numbers is 1. | |
# The method should return false otherwise. For example coprime?(25, 12) is true because | |
# 1 is the only number that divides both 25 and 12. | |
p coprime?(25, 12) # => true | |
p coprime?(7, 11) # => true | |
p coprime?(30, 9) # => false | |
p coprime?(6, 24) # => false | |
def coprime(numberOne, numberTwo) | |
2..numberOne-1.each do |divisor| | |
if (divisor % numberTwo == 0) && (divisor % numberOne == 0) | |
return false | |
end | |
end | |
return true | |
end | |
ERRORS | |
Rickys-MacBook-Pro:ricky_arora_advanced_methods_exercise Rtyer$ ruby 01_coprime.rb | |
01_coprime.rb:16: void value expression | |
end | |
^ | |
01_coprime.rb:16: syntax error, unexpected '\n', expecting => | |
end | |
^ | |
01_coprime.rb:19: syntax error, unexpected '}', expecting keyword_end | |
Rickys-MacBook-Pro:ricky_arora_advanced_methods_exercise Rtyer$ ruby 01_coprime.rb | |
01_coprime.rb:16: void value expression | |
end | |
^ | |
01_coprime.rb:16: syntax error, unexpected '\n', expecting => | |
end | |
^ | |
01_coprime.rb:20: syntax error, unexpected '}', expecting end-of-input | |
Rickys-MacBook-Pro:ricky_arora_advanced_methods_exercise Rtyer$ ruby 01_coprime.rb | |
01_coprime.rb:16: void value expression | |
end | |
^ | |
01_coprime.rb:16: syntax error, unexpected '\n', expecting => | |
end | |
^ | |
01_coprime.rb:20: syntax error, unexpected '}', expecting end-of-input | |
Rickys-MacBook-Pro:ricky_arora_advanced_methods_exercise Rtyer$ ruby 01_coprime.rb | |
01_coprime.rb:17: syntax error, unexpected '\n', expecting => | |
end | |
^ | |
01_coprime.rb:20: syntax error, unexpected '}', expecting end-of-input | |
Rickys-MacBook-Pro:ricky_arora_advanced_methods_exercise Rtyer$ ruby 01_coprime.rb | |
01_coprime.rb:17: syntax error, unexpected '\n', expecting => | |
end | |
^ | |
01_coprime.rb:20: syntax error, unexpected '}', expecting end-of-input | |
Rickys-MacBook-Pro:ricky_arora_advanced_methods_exercise Rtyer$ ruby 01_coprime.rb | |
Traceback (most recent call last): | |
01_coprime.rb:7:in `<main>': undefined method `coprime?' for main:Object (NoMethodError) | |
Rickys-MacBook-Pro:ricky_arora_advanced_methods_exercise Rtyer$ ruby 01_coprime.rb | |
Traceback (most recent call last): | |
01_coprime.rb:7:in `<main>': undefined method `coprime?' for main:Object (NoMethodError) | |
Rickys-MacBook-Pro:ricky_arora_advanced_methods_exercise Rtyer$ ruby 01_coprime.rb | |
Traceback (most recent call last): | |
01_coprime.rb:7:in `<main>': undefined method `coprime?' for main:Object (NoMethodError) | |
Rickys-MacBook-Pro:ricky_arora_advanced_methods_exercise Rtyer$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment