A cyclops number is a number with an odd number of digits that has a zero in the center, but nowhere else. They are named so in tribute to the one eyed giants Cyclops from Greek mythology.

Cyclops numbers can be found in any base. This task strictly is looking for cyclops numbers in base 10.

There are many different classifications of cyclops numbers with minor differences in characteristics. In an effort to head off a whole series of tasks with tiny variations, we will cover several variants here.



Task
 Find and display here on this page the first 50 cyclops numbers in base 10 (all of the sub tasks are restricted to base 10).
 Find and display here on this page the first 50 prime cyclops numbers. (cyclops numbers that are prime.)
 Find and display here on this page the first 50 blind prime cyclops numbers. (prime cyclops numbers that remain prime when "blinded"; the zero is removed from the center.)
 Find and display here on this page the first 50 palindromic prime cyclops numbers. (prime cyclops numbers that are palindromes.)


Stretch
 Find and display the first cyclops number greater than ten million (10,000,000) and the index (place) in the series where it is found.
 Find and display the first prime cyclops number greater than ten million (10,000,000) and the index (place) in the series where it is found.
 Find and display the first blind prime cyclops number greater than ten million (10,000,000) and the index (place) in the series where it is found.
 Find and display the first palindromic prime cyclops number greater than ten million (10,000,000) and the index (place) in the series where it is found.
(Note: there are no cyclops numbers between ten million and one hundred million, they need to have an odd number of digits)



See also
 OEIS A134808 - Cyclops numbers
 OEIS A134809 - Cyclops primes
 OEIS A329737 - Cyclops primes that remain prime after being "blinded"
 OEIS A136098 - Prime palindromic cyclops numbers




require 'prime'
 
NONZEROS = %w(1 2 3 4 5 6 7 8 9)
 
cyclopes = Enumerator.new do |y|
  (0..).each do |n|
    NONZEROS.repeated_permutation(n) do |lside|
      NONZEROS.repeated_permutation(n) do |rside|
        y << (lside.join + "0" + rside.join).to_i
      end
    end
  end
end
 
prime_cyclopes             = Enumerator.new {|y| cyclopes.each {|c| y << c if c.prime?} }
blind_prime_cyclopes       = Enumerator.new {|y| prime_cyclopes.each {|c| y << c if c.to_s.delete("0").to_i.prime?} }
palindromic_prime_cyclopes = Enumerator.new {|y| prime_cyclopes.each {|c| y << c if c.to_s == c.to_s.reverse} }
 
n, m = 50, 10_000_000
["cyclopes", "prime cyclopes", "blind prime cyclopes", "palindromic prime cyclopes"].zip(
[cyclopes, prime_cyclopes, blind_prime_cyclopes, palindromic_prime_cyclopes]).each do |name, enum|
  cycl, idx = enum.each_with_index.detect{|n, i| n > m}
  puts "The first #{n} #{name} are: \n#{enum.take(n).to_a}\nFirst #{name} term > #{m}: #{cycl} at index: #{idx}.", ""
end
 