Posted By

rtperson on 07/07/11


Tagged

Hanoi DataBits


Versions (?)

Towers of Hanoi by Bit Twiddling


 / Published in: Haskell
 

URL: http://codereview.stackexchange.com/questions/1684/towers-of-hanoi-in-haskell

Credit where it's due: I got this from udpn over at codereview.stackexchange.com. I'm just putting it here for further study.

  1. import Data.Bits
  2.  
  3. hanoiBits :: Int -> [(Int, Int)]
  4. hanoiBits n = init $ map (\x -> ((x .&. (x-1)) `mod` 3, ((x .|. (x-1)) + 1) `mod` 3)) [1..shift 1 n]

Report this snippet  

You need to login to post a comment.