diff options
| author | pjungeblut <paul.jungeblut@gmail.com> | 2014-11-25 23:38:01 +0100 |
|---|---|---|
| committer | pjungeblut <paul.jungeblut@gmail.com> | 2014-11-25 23:38:01 +0100 |
| commit | 1580486eda52a91b206691e5cfff5b8460f2206e (patch) | |
| tree | eb912f268742b6f4251fe48f20eaff8097dfb058 /sonstiges/josephusK.cpp | |
| parent | ac2c261f2c662f021c1016f18998a621c3ba0eaa (diff) | |
Josephus Code
Diffstat (limited to 'sonstiges/josephusK.cpp')
| -rw-r--r-- | sonstiges/josephusK.cpp | 4 |
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 |
