summaryrefslogtreecommitdiff
path: root/sonstiges/josephus2.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/josephus2.cpp
parent2c133b76f193478bb85d41a76ae78695cc067452 (diff)
parent24507ee02a8fe20fb22ae30642e3b15e411e82eb (diff)
merge
Diffstat (limited to 'sonstiges/josephus2.cpp')
-rw-r--r--sonstiges/josephus2.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/sonstiges/josephus2.cpp b/sonstiges/josephus2.cpp
new file mode 100644
index 0000000..7676e3c
--- /dev/null
+++ b/sonstiges/josephus2.cpp
@@ -0,0 +1,8 @@
+int rotateLeft(int n) { //returns the number of the last survivor (1 based)
+ for (int i = 31; i >= 0; i--)
+ if (n & (1 << i)) {
+ n &= ~(1 << i);
+ break;
+ }
+ n <<= 1; n++; return n;
+} \ No newline at end of file