I have found the following code for solving the Towers of Hanoi. The code is working fine! But I cannot understand what's going on exactly.
import Data.Bits
hanoi :: Int -> [(Int, Int)]
hanoi n = map (\x -> ((x .&. (x-1)) `mod` 3, ((x .|. (x-1)) + 1) `mod` 3)) [1..shift 1 n]
main = print $ hanoi 5
Can anybody explain this code? Thanks