Replace Pioneer Home   All Examples   Free Download  RSS: Replace Pioneer Examples

1317.Text generator -- How to generate all palindromic prime with specified length?

 User: lijing -- 2015-09-02          << 1316  1318 >> Hits: 1679 Type: Text generator Search all Text generator examples Description: Palindromic prime The first few palindromic prime: 11,101,131,151,181,191,313,353,373,383,727,757,787,797,919,929 ...... two palindromic prime 1, three palindromic prime 15, five palindromic prime 93, seven palindromic prime 668, nine palindromic prime 5172.  Whether the number is listed between palindromic prime 1000-999999999  thanks.  If you can achieve the purpose. The number of digits to 15(1000000000-100000000000000) can be achieved?  List all palindromic prime. Output Sample: p_prime(2): total:1,  p_prime(3): total:15 p_prime(5): total:93 p_prime(7): total:668  p_prime(9): total:5172, time:11 seconds 100030001 100050001 ... 999686999 999727999 p_prime(11): total:42042, time:14 minutes 10000500001 10000900001 ... 99998989999 99999199999 p_prime(>11): too slow Answer: Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps. 1. ctrl-h open 'replace' window * set 'replace with pattern' to: join("\n", p_prime(9)) * click 'advanced' tab, set 'run following at the beginning of replace' to: sub prime_list { my \$n=shift; my @p; for(my \$i=3; \$i<\$n; \$i+=2) { \$p[\$i]=\$i;} my \$s=sqrt(\$n); for(my \$i=3; \$i<\$s; \$i+=2) { if (\$p[\$i]) { for(my \$j=\$i*\$i; \$j<\$n; \$j+=\$i+\$i) { \$p[\$j] = 0 } } } return grep{\$_}@p; } sub is_prime { my (\$n,\$p) = @_; my \$s=sqrt(\$n); for(@\$p) { return 1 if \$_ > \$s; return 0 if !(\$n % \$_); } return 1 } sub p_prime { my \$len=shift; return (2) if \$len==2; return () if !(\$len%2); my @pp; my \$n = \$len/2-1; my @p = prime_list(32*(10**\$n)); for my \$j(1,3,7,9) { for my \$i('0'x\$n..'9'x\$n) { my \$r=reverse(\$i); map{push @pp,"\$j\$i\$_\$r\$j" if is_prime("\$j\$i\$_\$r\$j", \@p)}(0..9) } } return @pp; }  3. click 'replace', done. Screenshot 1:  Replace_Window Screenshot 2:  Replace_Advanced_Window Similar Examples: How to rip out all but line 1 and specified text? (60%)How to sort all lines of text by specified keyword? (59%)How to shuffle all lines of text in specified range? (58%)How to re-group all elements in specified range? (57%)How to extract all lines containing words in specified file? (57%)How to extract all lines with specified date range from text file? (57%)How to delete all lines containing specific word in specific column? (56%)How to generate an html page that include download links of specified files? (55%) Check Demo of Text generator Keywords: 101  digits  even  grep  reverse  1 13  length  return  two  digit  first three  return tab  replace all digits  number length  first two  the first two  first 10  length replace