RosettaCodeData/Task/Josephus-problem/Zkl/josephus-problem-2.zkl
2017-09-25 22:28:19 +02:00

9 lines
232 B
Text

fcn j2(n,k,m){
reg p=[0..n-1].walk().copy(), i=0, seq=L();
while(p.len()>m){
i=(i+k-1)%p.len();
seq.append(p.pop(i));
}
"Prisoner killing order: %s.\nSurvivors: [%s]"
.fmt(seq.concat(","),p.concat(","))
}