Skip to content

Instantly share code, notes, and snippets.

@antimon2
Created September 29, 2012 03:39
Show Gist options
  • Save antimon2/3803081 to your computer and use it in GitHub Desktop.
Save antimon2/3803081 to your computer and use it in GitHub Desktop.
Project Euler 69
require 'prime'
class Integer
def phi
self.prime_division.inject(1){|m,(p,k)|m*=p**k-p**(k-1)}
end
def phi_ratio
self.to_f / self.phi
end
end
def project_euler_69 n_max=1_000_000
(2..n_max).max_by(&:phi_ratio)
end
if $0 == __FILE__
p project_euler_69
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment