-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem35.rb
More file actions
31 lines (28 loc) · 767 Bytes
/
problem35.rb
File metadata and controls
31 lines (28 loc) · 767 Bytes
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
require("./utils")
class Problem35
def Problem35.run
circular_primes = []
primes = Utils.get_primes(1_000_000)
primes_to_check = primes.clone
primes_to_check.each do |p|
string_p = String(p)
if string_p.length == 1
circular_primes << p
else
circulars = []
(0...string_p.length).each do |d|
next_circular = ""
(0...string_p.length).each do |i|
next_circular += string_p[i-d..i-d]
end
circulars << Integer(next_circular) if next_circular[0..0] != '0'
end
if circulars.all?{|x| primes.include?(x)}
circular_primes << p
primes_to_check -= circulars
end
end
end
puts circular_primes.length
end
end