Skip to content

Instantly share code, notes, and snippets.

@aghull
Created November 26, 2012 02:34
Show Gist options
  • Save aghull/4146286 to your computer and use it in GitHub Desktop.
Save aghull/4146286 to your computer and use it in GitHub Desktop.
class Fixnum
def factors
(1..self).select { |f| modulo(f) == 0 }.uniq
end
def prime?
equal? 1 or factors == [1, self]
end
def coprime?(b)
hcf(b) == 1
end
def hcf(other)
one = self
while (one > 0 and other > 0) do
one, other = [one, other].sort
other %= one
end
return [one, other].max
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment