This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| body { | |
| color:green; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| def findAnomalyPosition(n): | |
| bit_length = int(math.ceil(math.log(n, 2))) | |
| #1010 & 0011 = 0010 It means and of any number to 33 << i is returning two consequitive bits at position i and i + 1 | |
| #XOR of n eith 2**i is toggling the bit at position i | |
| #so XOR n with 3 >> i is toggling bits at positions i and i + 1 and in our case | |
| #if bits in position i and i + 1 is 2 or 10 we want to make 01 which is this toggling with number 3 | |
| return [i for i in range(but_length) if ((x >> i) & 3) == 2 if ((x >> i) & 3) == 2] | |
| def generateNext(x): |
NewerOlder