Towers of Hanoi by Bit Twiddling


/ Published in: Haskell
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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]

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.