Last active
August 17, 2016 05:31
-
-
Save craftybones/582e0220e6331df7d24dff0d887a8cd9 to your computer and use it in GitHub Desktop.
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
class Fixnum | |
def is_prime? | |
2.upto(self-1).none? do |y| | |
self%y==0 | |
end | |
end | |
def prime_factors | |
2.upto(self).select do |x| | |
self%x==0 && x.is_prime? | |
end | |
end | |
end | |
def can_she_equalise? a,xyz | |
pf=a.map(&:prime_factors) | |
result=((pf.flatten-pf.reduce(&:&))-xyz).empty? | |
result ? "She can" : "She can't" | |
end | |
puts can_she_equalise?([2,4],[2]) | |
puts can_she_equalise?([2,6,7],[2,3]) | |
puts can_she_equalise?([49,98],[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment