first commit

This commit is contained in:
=
2024-02-07 15:06:50 +01:00
commit af02e453c1
55 changed files with 2166 additions and 0 deletions

32
p24/solution.jl Normal file
View File

@@ -0,0 +1,32 @@
function solution(V, p)
l = length(V)
n = factorial(l)
if p > n
print("p too large")
return
end
sort!(V)
m = n
r = p
vals = zeros(Int, l-1)
for i 0:(l-2)
m = div(m, l-i)
vals[i+1] = cld(r, m)
r = mod(r-1, m)+1
end
sol = zeros(Int, l)
V = copy(V)
for i 1:(l-1)
sol[i] = popat!(V, vals[i])
end
sol[l] = pop!(V)
return sol
end
function printsols(V)
for i 1:factorial(length(V))
println(solution(V, i))
end
end