[seqfan] Re: Most efficient way to construct a list of pandigital palindromic numbers?

Hans Havermann pxp at rogers.com
Fri Dec 11 15:20:44 CET 2009


> ... I was looking at sequential-permutation operators
> in Mathematica earlier and there are "Combinatorica"
> add-on functions such as NextPermutation[p] which gives
> the permutation following p in lexicographic order...
>
>> (For the record, I find 78695 19-digit numbers.)
>
> Quick, how many 20-digit numbers? ;)

A postscript to my above comments and Douglas McNeil's co-calculation  
of all 78695 19-digit pandigital palindromic primes. I subsequently  
generated all 4232506 21-digit PPPs (89 MB, if anyone is interested).  
A 23-digit attempt using Mathematica's Permutations function did not  
have enough memory, so I rewrote the program to use that  
NextPermutation function and discovered, after some head-scratching,  
that NextPermutation does NOT step as expected through all the  
Permutations of a list when that list contains multiple items:

Permutations[{0,0,1,2}]

{{0,0,1,2},{0,0,2,1},{0,1,0,2},{0,1,2,0},{0,2,0,1},{0,2,1,0},{1,0,0,2}, 
{1,0,2,0},{1,2,0,0},{2,0,0,1},{2,0,1,0},{2,1,0,0}}

NextPermutation[{0,2,1,0}]

{0,0,1,2}

NextPermutation[{1,2,0,0}]

{1,2,0,0}




More information about the SeqFan mailing list