[Codewars] Mystery Function

Mystery Function

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ulong mystery(ulong n){
return n ^ (n >> 1);
}

ulong mysteryInv(ulong n){
ulong mask = n >> 1;
while(mask) {
n ^= mask;
mask >>= 1;
}
return n;
}

std::string nameOfMystery(){
return "Gray code";
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/05/07/PS/Codewars/mystery-function/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.