Pandigital prime: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (added Arturo) |
(Added XPL0 example.) |
||
Line 778: | Line 778: | ||
The largest pandigital decimal prime which uses all the digits 0..n once is: |
The largest pandigital decimal prime which uses all the digits 0..n once is: |
||
76,540,231 |
76,540,231 |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
The largest pandigital number not evenly divisible by 3 is 76543210. This |
|||
is because any number whose digits add to a multiple of 3 is evenly |
|||
divisible by 3, and 8+7+6+5+4+3+2+1+0 = 36 and adding 9 = 45, both of |
|||
which are evenly divisible by 3. |
|||
<syntaxhighlight lang "XPL0">func IsPrime(N); \Return 'true' if N is prime |
|||
int N, D; |
|||
[if N < 2 then return false; |
|||
if (N&1) = 0 then return N = 2; |
|||
if rem(N/3) = 0 then return N = 3; |
|||
D:= 5; |
|||
while D*D <= N do |
|||
[if rem(N/D) = 0 then return false; |
|||
D:= D+2; |
|||
if rem(N/D) = 0 then return false; |
|||
D:= D+4; |
|||
]; |
|||
return true; |
|||
]; |
|||
func Pandigital(N, Set); \Return 'true' if N is pandigital |
|||
int N, Set, Used; |
|||
[Used:= 0; |
|||
while N do |
|||
[N:= N/10; |
|||
if Used & 1<<rem(0) then return false; |
|||
Used:= Used ! 1<<rem(0); |
|||
]; |
|||
return Used = Set; |
|||
]; |
|||
int Data, Task, N, Set; |
|||
[Data:= ["1..7: ", 7654321, %1111_1110, "0..7: ", 76543210-1\odd\, %1111_1111]; |
|||
for Task:= 0 to 1 do |
|||
[Text(0, Data(Task*3+0)); |
|||
N:= Data(Task*3+1); Set:= Data(Task*3+2); |
|||
loop [if IsPrime(N) then |
|||
if Pandigital(N, Set) then |
|||
[IntOut(0, N); quit]; |
|||
N:= N-2; |
|||
]; |
|||
CrLf(0); |
|||
]; |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1..7: 7652413 |
|||
0..7: 76540231 |
|||
</pre> |
</pre> |