Problem 35

Ruby

 1count = 0
 2counter = 1
 3
 4def prime?(num)
 5  if (num % 2).zero?
 6    false
 7  else
 8    iterator = 3
 9    while iterator < Math.sqrt(num)
10      false if (num % iterator).zero?
11      iterator += 1
12    end
13    true
14  end
15end
16
17loop do
18  is_circular_prime = true
19  break if counter == 1_000_000
20  puts "Counter: #{counter}"
21  arr = counter.to_s.chars.to_a.permutation.to_a
22  arr.map{ |x|  if prime?(x.join.to_s.to_i) == false
23           is_circular_prime = false
24  end
25  }
26  count += 1 if is_circular_prime == true
27  counter += 1
28end
29puts count