March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
8
Task/Josephus-problem/Julia/josephus-problem-1.julia
Normal file
8
Task/Josephus-problem/Julia/josephus-problem-1.julia
Normal 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
|
||||
3
Task/Josephus-problem/Julia/josephus-problem-2.julia
Normal file
3
Task/Josephus-problem/Julia/josephus-problem-2.julia
Normal 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
|
||||
9
Task/Josephus-problem/Julia/josephus-problem-3.julia
Normal file
9
Task/Josephus-problem/Julia/josephus-problem-3.julia
Normal 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
|
||||
3
Task/Josephus-problem/Julia/josephus-problem-4.julia
Normal file
3
Task/Josephus-problem/Julia/josephus-problem-4.julia
Normal 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]
|
||||
Loading…
Add table
Add a link
Reference in a new issue