summaryrefslogtreecommitdiff
path: root/content/other/josephus2.cpp
diff options
context:
space:
mode:
authormzuenni <michi.zuendorf@gmail.com>2024-08-30 15:04:20 +0200
committermzuenni <michi.zuendorf@gmail.com>2024-08-30 15:04:20 +0200
commitac2d9ad3f2c88bc12420fc439e8d0b4775a11169 (patch)
tree256c13ae0a321e3a705bde52ee679131b9f864d5 /content/other/josephus2.cpp
parent00b01a954304e50904de97b25639c535e16f259e (diff)
various small improvements
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;
}