Skip to content

Instantly share code, notes, and snippets.

@xeago
Created July 20, 2013 19:05
Show Gist options
  • Save xeago/6046105 to your computer and use it in GitHub Desktop.
Save xeago/6046105 to your computer and use it in GitHub Desktop.
Usage: 10.phi #=> 4
class Integer
def phi
fractions = self.prime_division
primes = fractions.map { |b,e| b }
rationals = primes.map {|p| Rational(p-1,p) }
return (rationals.reduce { |a,b| a*b } * self).to_i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment