Solutions for Swap Odd and Even

    • @GarretVam
    • @mason, submitted in Python 2, achived 100% score
    def solve(x) : 
    
        # Get all even bits of x 
        even_bits = x & 0xAAAAAAAA
    
        # Get all odd bits of x 
        odd_bits = x & 0x55555555
    
        # Right shift even bits 
        even_bits >>= 1
    
        # Left shift odd bits 
        odd_bits <<= 1 
    
        # Combine even and odd bits 
        return (even_bits | odd_bits)  
    
    • @GarretVam
    • @mason, submitted in Python 3, achived 100% score
    def solve(x) : 
    
        # Get all even bits of x 
        even_bits = x & 0xAAAAAAAA
    
        # Get all odd bits of x 
        odd_bits = x & 0x55555555
    
        # Right shift even bits 
        even_bits >>= 1
    
        # Left shift odd bits 
        odd_bits <<= 1 
    
        # Combine even and odd bits 
        return (even_bits | odd_bits)