-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path060.rb
32 lines (28 loc) · 910 Bytes
/
060.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
exit
end
end
end
end
end