summaryrefslogtreecommitdiff
path: root/sonstiges/josephusK.cpp
diff options
context:
space:
mode:
authorPaul Jungeblut <s_jungeb@i08pc79.atis-stud.uni-karlsruhe.de>2014-11-26 11:46:02 +0100
committerPaul Jungeblut <s_jungeb@i08pc79.atis-stud.uni-karlsruhe.de>2014-11-26 11:46:02 +0100
commit7a217262958cdf11dfb1f90b86df31acde90ff45 (patch)
tree8d96850058853910ebf2ef75827b0862180fd0c1 /sonstiges/josephusK.cpp
parent2c133b76f193478bb85d41a76ae78695cc067452 (diff)
parent24507ee02a8fe20fb22ae30642e3b15e411e82eb (diff)
merge
Diffstat (limited to 'sonstiges/josephusK.cpp')
-rw-r--r--sonstiges/josephusK.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/sonstiges/josephusK.cpp b/sonstiges/josephusK.cpp
new file mode 100644
index 0000000..e3fcac2
--- /dev/null
+++ b/sonstiges/josephusK.cpp
@@ -0,0 +1,4 @@
+int josephus(int n, int k) { //returns the number of the last survivor (0 based)
+ if (n == 1) return 0;
+ return (josephus(n - 1, k) + k) % n;
+} \ No newline at end of file