Pandigital prime
Pandigital prime is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
- Task
The following problem is taken from Project Euler.
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?
Ring
<lang ring> load "stdlib.ring" see "working..." + nl see "The largest pandigital prime is:" + nl
limit = 7652413
for n = limit to 2 step -2
flag = 1 strn = string(n) if isprime(n) for m = 1 to len(strn) ind = count(strn,strn[m]) if ind != 1 flag = 0 ok next if flag = 1 pand = n exit ok ok
next
see "" + pand + nl
see "done..." + nl
func count(cString,dString)
sum = 0 while substr(cString,dString) > 0 sum++ cString = substr(cString,substr(cString,dString)+len(string(sum))) end return sum
</lang>
- Output:
The largest pandigital prime is: 9,876,413