Created
September 29, 2012 03:39
-
-
Save antimon2/3803081 to your computer and use it in GitHub Desktop.
Project Euler 69
This file contains 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
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