Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
17
Task/Josephus-problem/D/josephus-problem-2.d
Normal file
17
Task/Josephus-problem/D/josephus-problem-2.d
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import std.stdio, std.algorithm, std.range;
|
||||
|
||||
int[][] Josephus(in int n, int k, int s=1) {
|
||||
int[] ks, ps = n.iota.array;
|
||||
for (int i=--k; ps.length>s; i=(i+k)%ps.length) {
|
||||
ks ~= ps[i];
|
||||
ps = remove(ps, i);
|
||||
}
|
||||
writefln("Josephus(%d,%d,%d) -> %(%d %) / %(%d %)%s", n, k, s, ps, ks[0..min($,45)], ks.length<45 ? "" : " ..." );
|
||||
return [ps, ks];
|
||||
}
|
||||
|
||||
void main() {
|
||||
Josephus(5, 2);
|
||||
Josephus(41, 3);
|
||||
Josephus(23482, 3343, 3);
|
||||
}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue