summaryrefslogtreecommitdiff
path: root/content/other/josephus2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'content/other/josephus2.cpp')
-rw-r--r--content/other/josephus2.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/content/other/josephus2.cpp b/content/other/josephus2.cpp
index 5086e13..33544ea 100644
--- a/content/other/josephus2.cpp
+++ b/content/other/josephus2.cpp
@@ -1,8 +1,5 @@
int rotateLeft(int n) { // Der letzte Überlebende, 1-basiert.
- for (int i = 31; i >= 0; i--) {
- if (n & (1 << i)) {
- n &= ~(1 << i);
- break;
- }}
- n <<= 1; n++; return n;
+ int bits = __lg(n);
+ n ^= 1 << bits;
+ return 2 * n + 1;
}