Cyclops numbers

From Rosetta Code
Revision as of 20:52, 23 June 2021 by Thundergnat (talk | contribs) (Draft Task and Raku example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Draft 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 one million (1,000,000) and the index (place) in the series where it is found.
  • Find and display the first prime cyclops number greater than one million (1,000,000) and the index (place) in the series where it is found.
  • Find and display the first blind prime cyclops number greater than one million (1,000,000) and the index (place) in the series where it is found.
  • Find and display the first palindromic prime cyclops number greater than one million (1,000,000) and the index (place) in the series where it is found.


See also


Raku

<lang perl6>my @cyclops = lazy gather for 0..* -> $exp {

 (exp($exp, 10) ..^ exp($exp + 1, 10)).map: -> $start {
      next if $start.contains: 0;
      for exp($exp, 10) ..^ exp($exp + 1, 10) -> $end {
          next if $end.contains: 0;
          take $start ~ 0 ~ $end;
      }
  }

}

my @prime-cyclops = @cyclops.grep: { .is-prime };

my @blind-cyclops = @prime-cyclops.grep: { .trans('0' => ).is-prime };

my @palindrome-cyclops = @prime-cyclops.grep: { $_ eq .flip };

for , @cyclops,

   'prime ',             @prime-cyclops,
   'blind prime ',       @blind-cyclops,
   'palindromic prime ', @palindrome-cyclops
 -> $type, $iterator {
   say "\n\nFirst 50 {$type}cyclops numbers:\n" ~ $iterator[^50].batch(10)».fmt("%7d").join("\n") ~
       "\n\nFirst {$type}cyclops number > 1,000,000: " ~ $iterator.first( * > 1e7 ) ~
       " - at (zero based) index: " ~ $iterator.first: * > 1e7, :k;

}</lang>

Output:
First 50 cyclops numbers:
    101     102     103     104     105     106     107     108     109     201
    202     203     204     205     206     207     208     209     301     302
    303     304     305     306     307     308     309     401     402     403
    404     405     406     407     408     409     501     502     503     504
    505     506     507     508     509     601     602     603     604     605

First cyclops number > 1,000,000: 111101111 - at (zero based) index: 538083


First 50 prime cyclops numbers:
    101     103     107     109     307     401     409     503     509     601
    607     701     709     809     907   11027   11047   11057   11059   11069
  11071   11083   11087   11093   12011   12037   12041   12043   12049   12071
  12073   12097   13033   13037   13043   13049   13063   13093   13099   14011
  14029   14033   14051   14057   14071   14081   14083   14087   15013   15017

First prime cyclops number > 1,000,000: 111101129 - at (zero based) index: 39319


First 50 blind prime cyclops numbers:
    101     103     107     109     307     401     503     509     601     607
    701     709     809     907   11071   11087   11093   12037   12049   12097
  13099   14029   14033   14051   14071   14081   14083   14087   15031   15053
  15083   16057   16063   16067   16069   16097   17021   17033   17041   17047
  17053   17077   18047   18061   18077   18089   19013   19031   19051   19073

First blind prime cyclops number > 1,000,000: 111101161 - at (zero based) index: 11393


First 50 palindromic prime cyclops numbers:
    101   16061   31013   35053   38083   73037   74047   91019   94049 1120211
1150511 1160611 1180811 1190911 1250521 1280821 1360631 1390931 1490941 1520251
1550551 1580851 1630361 1640461 1660661 1670761 1730371 1820281 1880881 1930391
1970791 3140413 3160613 3260623 3310133 3380833 3460643 3470743 3590953 3670763
3680863 3970793 7190917 7250527 7310137 7540457 7630367 7690967 7750577 7820287

First palindromic prime cyclops number > 1,000,000: 114808411 - at (zero based) index: 66