summaryrefslogtreecommitdiff
path: root/sonstiges/josephus2.cpp
blob: 7676e3cf524cd25bab7b2e3a445c0c378d429716 (plain)
1
2
3
4
5
6
7
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;
}