Pandigital prime: Difference between revisions
→{{header|Wren}}: Combined the two versions into 1.
(→Algol 68: Digits 0 to n: fix comment) |
(→{{header|Wren}}: Combined the two versions into 1.) |
||
Line 468:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<br>
This makes use of the optimization strategy in the Factor entry to do both the basic and optional tasks.
<lang ecmascript>import "/math" for Int
import "/fmt" for Fmt
Line 483:
while (a[i] > a[i+1]) i = i - 1
while (a[j] < a[i]) j = j - 1
a[i] = a[j]▼
j = n
i = i + 1
while (i < j) {
a[i] = a[j]▼
a[j] = t▼
i = i + 1
j = j - 1
Line 500 ⟶ 496:
}
System.print("The largest pandigital decimal prime which uses all the digits 1..n once is:")▼
▲for (n in [7, 4]) {
▲ System.print("The largest pandigital decimal prime which uses all the digits
for (
if (perms[i][
if (Int.isPrime(p)) {▼
Fmt.print("$,d\n", p)▼
}
}
}</lang>
Line 517 ⟶ 518:
The largest pandigital decimal prime which uses all the digits 1..n once is:
7,652,413
▲ var perms = [input]
▲ if (perms[i][0] == "0" || perms[i][-1] % 2 == 0 || perms[i][-1] == 5) continue
▲ Fmt.print("$,d", p)
The largest pandigital decimal prime which uses all the digits 0..n once is:
76,540,231
|