• + 4 comments

    This is pretty cleaver. Took me a minute or to to figure out why it works. For those that want to learn it's in how the & operator works

    say we start out with 5869

    5869 = 1011011101101
    <<1  = 0110111011010
    &    = 0010011001000  = 1224
    
    <<1  = 0100110000000
    &      0000010000000  = 128
    
    <<1  = 0000100000000
    &    = 0000000000000  = 0
    

    thats 3 cycles. which is the answer. I love simple elegant solutions. too many of the newer languages have too many steps.