March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -0,0 +1,8 @@
function j(n,k)
p, i, seq=[0:n-1], 0, Int[]
while !isempty(p)
i=(i+k-1)%length(p)
push!(seq,splice!(p,i+1))
end
@sprintf("Prisoner killing order: %s.\nSurvivor: %i",replace(chomp(string(seq[1:end-1])),"\n",", "),seq[end])
end

View file

@ -0,0 +1,3 @@
julia> print(j(41,3))
Prisoner killing order: 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 0, 4, 9, 13, 18, 22, 27, 31, 36, 40, 6, 12, 19, 25, 33, 39, 7, 16, 28, 37, 10, 24, 1, 21, 3, 34, 15.
Survivor: 30

View file

@ -0,0 +1,9 @@
function j2(n,k,m)
p, i, seq=[0:n-1], 0, Int[]
while length(p)>m
i=(i+k-1)%length(p)
push!(seq,splice!(p,i+1))
end
prt_array(x)=replace(chomp(string(x)),"\n",", ")
@sprintf("Prisoner killing order: %s.\nSurvivors: %s",prt_array(seq),"["*prt_array(p)*"]")
end

View file

@ -0,0 +1,3 @@
julia> print(j2(41,3,3))
Prisoner killing order: 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 0, 4, 9, 13, 18, 22, 27, 31, 36, 40, 6, 12, 19, 25, 33, 39, 7, 16, 28, 37, 10, 24, 1, 21, 3.
Survivors: [15, 30, 34]