September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
20
Task/Josephus-problem/Phix/josephus-problem.phix
Normal file
20
Task/Josephus-problem/Phix/josephus-problem.phix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
function Josephus(sequence prisoners, integer step, survivors)
|
||||
integer n = length(prisoners), nn = n
|
||||
integer p = 0
|
||||
while n>survivors do
|
||||
integer found = 0
|
||||
while found!=step do
|
||||
p = iff(p=nn?1:p+1)
|
||||
found += prisoners[p]!=-1
|
||||
end while
|
||||
-- (if you want a kill list, build it here!)
|
||||
prisoners[p] = -1
|
||||
n -= 1
|
||||
end while
|
||||
return remove_all(-1,prisoners)
|
||||
end function
|
||||
|
||||
?Josephus(tagset(5),2,1)
|
||||
?Josephus(tagset(41),3,1)
|
||||
?Josephus(tagset(41),3,3)
|
||||
?Josephus({"Joe","Jack","William","John","James"},2,1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue