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




with javascript_semantics
atom t0 = time()
function bump(sequence half)
    -- add a digit to valid halves
    -- eg {0} --> {1..9} (no zeroes)
    --        --> {11..99} ("")
    --        --> {111..999}, etc
    sequence res = {}
    for i=1 to length(half) do
        integer hi = half[i]*10
        for digit=1 to 9 do
            res &= hi+digit
        end for
    end for
    return res
end function

procedure cyclops(string s="")
    sequence res = {},
             half = {0} -- valid digits, see bump()
    integer left = 1,   -- half[] before the 0
            right = 0,  -- half[] after the 0
            hlen = 1,   -- length(half)
            cpow = 10,  -- cyclops power (of 10)
            bcpow = 1,  -- blind cyclops power
            cn = 0      -- cyclops number (scratch)
    bool valid = false,
         bPrime = match("prime",s),
         bBlind = match("blind",s),
         bPalin = match("palindromic",s)
    while length(res)<50 or cn<=1e7 or not valid do
        right += 1
        if right>hlen then
            right = 1
            left += 1
            if left>hlen then
                half = bump(half)
                hlen = length(half)
                cpow *= 10
                bcpow *= 10
                left = 1
            end if
        end if
        integer lh = half[left],
                rh = half[right]
        cn = lh*cpow+rh -- cyclops number
        valid = not bPrime or is_prime(cn)
        if valid and bBlind then
            valid = is_prime(lh*bcpow+rh)
        end if
        if valid and bPalin then
            valid = sprintf("%d",lh) == reverse(sprintf("%d",rh))
        end if
        if valid then
            res = append(res,sprintf("%7d",cn))
        end if
    end while
    printf(1,"First 50 %scyclops numbers:\n%s\n",{s,join_by(res[1..50],1,10)})
    printf(1,"First %scyclops number > 10,000,000: %s at (one based) index: %d\n\n",
             {s,res[$],length(res)})
end procedure

cyclops()
cyclops("prime ")
cyclops("blind prime ")
cyclops("palindromic prime ")
?elapsed(time()-t0)
