Jump to content

Pandigital prime: Difference between revisions

→‎{{header|Wren}}: Now uses Wren-perm.
(Added Sidef)
(→‎{{header|Wren}}: Now uses Wren-perm.)
Line 671:
 
=={{header|Wren}}==
{{libheader|Wren-perm}}
{{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 "./mathperm" for IntPerm
import "./fmtmath" for FmtInt
import "./fmt" for Fmt
 
// generates all permutations in lexicographical order
var permutations = Fn.new { |input|
var perms = [input]
var a = input.toList
var n = a.count - 1
for (c in 1...Int.factorial(n+1)) {
var i = n - 1
var j = n
while (a[i] > a[i+1]) i = i - 1
while (a[j] < a[i]) j = j - 1
a.swap(i, j)
j = n
i = i + 1
while (i < j) {
a.swap(i, j)
i = i + 1
j = j - 1
}
perms.add(a.toList)
}
return perms
}
 
for (start in 1..0) {
var outer = false
System.print("The largest pandigital decimal prime which uses all the digits %(start)..n once is:")
for (n in [7, 4]) {
var perms = permutationsPerm.calllistLex((start..n).toList)
for (i in perms.count - 1..0) {
if (perms[i][-1] % 2 == 0 || perms[i][-1] == 5 || (start == 0 && perms[i][0] == "0")) continue
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.