Skip to content

Instantly share code, notes, and snippets.

@craftybones
Last active August 17, 2016 05:31
Show Gist options
  • Save craftybones/582e0220e6331df7d24dff0d887a8cd9 to your computer and use it in GitHub Desktop.
Save craftybones/582e0220e6331df7d24dff0d887a8cd9 to your computer and use it in GitHub Desktop.
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