Created
May 30, 2012 00:39
-
-
Save kristenmills/2831717 to your computer and use it in GitHub Desktop.
Project Euler 70
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
def phi p1, p2 | |
(p1-1)*(p2-1) | |
end | |
def find | |
min = [0,2] | |
lst = prime_sieve 5000 | |
lst.keep_if{|x| x > 2000} | |
lst.reverse_each do |p1| | |
lst.reverse_each do |p2| | |
if p1*p2 <= 10**7 | |
n = p1*p2 | |
m = phi p1, p2.to_f | |
if min[1] > n/m && permutation?(n, m.to_i) | |
min = [n,n/m] | |
end | |
end | |
end | |
end | |
min[0] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment