We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
What is the largest n-digit pandigital prime that exists?
#all_perms #PrimeList def p41 digs=7 while true p=all_perms((1..digs).to_a).map{|a|a.join("").to_i}.select{|i|PrimeList.isPrime? i} if p.length>0 p.sort! puts p.last return end digs-=1 end end