RosettaCodeData/Task/Josephus-problem/Zkl/josephus-problem-2.zkl

10 lines
232 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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(","))
}