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

9 lines
219 B
Text

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