2016-12-05 22:15:40 +01:00
|
|
|
function j(n,k)
|
2014-04-02 16:56:35 +00:00
|
|
|
p, i, seq=[0:n-1], 0, Int[]
|
2016-12-05 22:15:40 +01:00
|
|
|
while !isempty(p)
|
2014-04-02 16:56:35 +00:00
|
|
|
i=(i+k-1)%length(p)
|
|
|
|
|
push!(seq,splice!(p,i+1))
|
|
|
|
|
end
|
2016-12-05 22:15:40 +01:00
|
|
|
@sprintf("Prisoner killing order: %s.\nSurvivor: %i",replace(chomp(string(seq[1:end-1])),"\n",", "),seq[end])
|
2014-04-02 16:56:35 +00:00
|
|
|
end
|