Skip to content

Instantly share code, notes, and snippets.

@kristenmills
Created May 30, 2012 00:39
Show Gist options
  • Save kristenmills/2831717 to your computer and use it in GitHub Desktop.
Save kristenmills/2831717 to your computer and use it in GitHub Desktop.
Project Euler 70
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