Superpermutation minimisation: Difference between revisions
Content added Content deleted
(Add Reference: A video of recent (2018) mathematical progress.) |
|||
Line 536: | Line 536: | ||
superPerm(10) len = 4037913 |
superPerm(10) len = 4037913 |
||
superPerm(11) len = 43954713</pre> |
superPerm(11) len = 43954713</pre> |
||
=={{header|Julia}}== |
|||
{{trans|D}} |
|||
<lang julia>const nmax = 12 |
|||
function superpermutation(n) |
|||
pos = 1 |
|||
count = zeros(nmax) |
|||
function r!(n, s) |
|||
if n == 0 |
|||
return false |
|||
end |
|||
c = s[pos + 1 - n] |
|||
count[n + 1] -= 1 |
|||
if count[n + 1] == 0 |
|||
count[n + 1] = n |
|||
if r!(n - 1, s) == 0 |
|||
return false |
|||
end |
|||
end |
|||
s[pos] = c |
|||
pos += 1 |
|||
return true |
|||
end |
|||
pos = n |
|||
superperm = zeros(UInt8, n < 2 ? n : mapreduce(factorial, +, 1:n)) |
|||
for i in 0:n-1 |
|||
count[i + 1] = i |
|||
superperm[i + 1] = Char(i + '0') |
|||
end |
|||
count[n + 1] = n |
|||
while r!(n, superperm) ; end |
|||
String(superperm) |
|||
end |
|||
function testsuper(N, verbose=false) |
|||
for i in 0:N-1 |
|||
s = superpermutation(i) |
|||
println("Superperm($i) has length $(length(s)) ", (verbose ? s : "")) |
|||
end |
|||
end |
|||
testsuper(nmax) |
|||
</lang>{{out}} |
|||
<pre> |
|||
Superperm(0) has length 0 |
|||
Superperm(1) has length 1 |
|||
Superperm(2) has length 3 |
|||
Superperm(3) has length 9 |
|||
Superperm(4) has length 33 |
|||
Superperm(5) has length 153 |
|||
Superperm(6) has length 873 |
|||
Superperm(7) has length 5913 |
|||
Superperm(8) has length 46233 |
|||
Superperm(9) has length 409113 |
|||
Superperm(10) has length 4037913 |
|||
Superperm(11) has length 43954713 |
|||
</pre> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |