From 1580486eda52a91b206691e5cfff5b8460f2206e Mon Sep 17 00:00:00 2001 From: pjungeblut Date: Tue, 25 Nov 2014 23:38:01 +0100 Subject: Josephus Code --- sonstiges/josephusK.cpp | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 sonstiges/josephusK.cpp (limited to 'sonstiges/josephusK.cpp') 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 -- cgit v1.2.3