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




/*REXX pgm finds 1st N cyclops (Θ) #s,  Θ primes,  blind Θ primes,  palindromic Θ primes*/
parse arg n cols .                               /*obtain optional argument from the CL.*/
if    n=='' |    n==","  then    n=   50         /*Not specified?  Then use the default.*/
if cols=='' | cols==","  then cols=   10         /* "      "         "   "   "     "    */
call genP                                        /*build array of semaphores for primes.*/
w= max(10, length( commas(@.#) ) )               /*max width of a number in any column. */
pri?= 0; bli?= 0; pal?= 0; call 0 ' first ' commas(n)                   " cyclops numbers"
pri?= 1; bli?= 0; pal?= 0; call 0 ' first ' commas(n)             " prime cyclops numbers"
pri?= 1; bli?= 1; pal?= 0; call 0 ' first ' commas(n)       " blind prime cyclops numbers"
pri?= 1; bli?= 0; pal?= 1; call 0 ' first ' commas(n) " palindromic prime cyclops numbers"
exit 0                                           /*stick a fork in it,  we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?;  do jc=length(?)-3  to 1  by -3; ?=insert(',', ?, jc); end;  return ?
/*──────────────────────────────────────────────────────────────────────────────────────*/
0: parse arg title;                idx= 1        /*get the title of this output section.*/
   say ' index │'center(title,   1 + cols*(w+1)     )      /*display the output title.  */
   say '───────┼'center(""   ,   1 + cols*(w+1), '─')      /*   "     "     "  separator*/
                   finds= 0;                 $=  /*the number of finds (so far); $ list.*/
     do j=0  until finds== n;      L= length(j)  /*find N cyclops numbers, start at 101.*/
     if L//2==0  then do;    j= left(1, L+1, 0)  /*Is J an even # of digits? Yes, bump J*/
                                        iterate  /*use a new J that has odd # of digits.*/
                      end
     z= pos(0, j);  if z\==(L+1)%2 then iterate  /* "  "    "    " (zero in mid)?    "  */
     if pos(0, j, z+1)>0           then iterate  /* "  "    "    " (has two 0's)?    "  */
     if pri?  then if \!.j         then iterate  /*Need a cyclops prime?      Then skip.*/
     if bli?  then do;   ?= space(translate(j, , 0), 0)   /*Need a blind cyclops prime ?*/
                         if \!.?   then iterate  /*Not a blind cyclops prime? Then skip.*/
                   end
     if pal?  then do;   r= reverse(j)           /*Need a palindromic cyclops prime?    */
                         if r\==j  then iterate  /*Cyclops number not palindromic? Skip.*/
                         if \!.r   then iterate  /*   "    palindrome not prime?     "  */
                   end
     finds= finds + 1                            /*bump the number of palindromic primes*/
     $= $ right( commas(j), w)                   /*add a palindromic prime ──►  $  list.*/
     if finds//cols\==0            then iterate  /*have we populated a line of output?  */
     say center(idx, 7)'│'  substr($, 2);    $=  /*display what we have so far  (cols). */
     idx= idx + cols                             /*bump the  index  count for the output*/
     end   /*j*/
   if $\==''  then say center(idx, 7)"│"  substr($, 2)  /*possible show residual output.*/
   say '───────┴'center(""  ,   1 + cols*(w+1), '─');  say
   return
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: !.= 0;  hip= 7890987 - 1                   /*placeholders for primes (semaphores).*/
      @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6=13 /*define some low primes.              */
      !.2=1; !.3=1; !.5=1; !.7=1; !.11=1; !.13=1 /*   "     "   "    "     flags.       */
                        #= 6;     sq.#= @.# ** 2 /*number of primes so far; prime square*/
        do j=@.#+2  by 2  for max(0, hip%2-@.#%2-1)     /*find odd primes from here on. */
        parse var   j   ''  -1  _                       /*get the last dec. digit of  J.*/
        if     _==5  then iterate;  if j// 3==0  then iterate  /*÷ by 5?  ÷ by 3?  Skip.*/
        if j// 7==0  then iterate;  if j//11==0  then iterate  /*÷  " 7?  ÷ by 11?   "  */
               do k=6  while sq.k<=j             /* [↓]  divide by the known odd primes.*/
               if j // @.k == 0  then iterate j  /*Is  J ÷ X?  Then not prime.     ___  */
               end   /*k*/                       /* [↑]  only process numbers  ≤  √ J   */
        #= #+1;    @.#= j;   sq.#= j*j;   !.j= 1 /*bump # Ps;  assign next P;  P sq; P# */
        end          /*j*/;               return