summaryrefslogtreecommitdiff
path: root/content/other/josephus2.cpp
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 15:39:23 +0100
committerGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 15:39:23 +0100
commit72bd993483453ed8ebc462f1a33385cd355d486f (patch)
treec5592ba1ed2fed79e26ba6158d097c9ceb43f061 /content/other/josephus2.cpp
parent98567ec798aa8ca2cfbcb85c774dd470f30e30d4 (diff)
parent35d485bcf6a9ed0a9542628ce4aa94a3326d0884 (diff)
merge mzuenni changes
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;
}