Skip to content

Commit

Permalink
060
Browse files Browse the repository at this point in the history
  • Loading branch information
obfuscoder committed Feb 13, 2013
1 parent c3c5152 commit 96ff4ad
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 060.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'prime'

@@all_primes = Prime.instance.each(1000000).to_a
@@primes_hash = @@all_primes.reduce({}){|h,e| h[e] = true; h}
@@primes = @@all_primes[0,1200]

class Integer
def prime?
@@primes_hash[self] ||= Prime.prime?(self)
end

def prime_combo?(n)
(self.to_s + n.to_s).to_i.prime? && (n.to_s + self.to_s).to_i.prime?
end
end

@@primes[0..-5].each_with_index do |a,ai|
@@primes[ai+1..-4].each_with_index do |b,bi|
next if !a.prime_combo?(b)
@@primes[bi+1..-3].each_with_index do |c,ci|
next if !a.prime_combo?(c) || !b.prime_combo?(c)
@@primes[ci+1..-2].each_with_index do |d,di|
next if !a.prime_combo?(d) || !b.prime_combo?(d) || !c.prime_combo?(d)
@@primes[di+1..-1].each do |e|
next if !a.prime_combo?(e) || !b.prime_combo?(e) || !c.prime_combo?(e) || !d.prime_combo?(e)
p [a,b,c,d,e, a+b+c+d+e]
end
end
end
end
end

0 comments on commit 96ff4ad

Please sign in to comment.