Showing posts with label Haskell. Show all posts
Showing posts with label Haskell. Show all posts

Sunday, June 6, 2010

haskell.org still down!

In case you were wondering, haskell.org has been down all weekend. I hopw it is back up soon. The 2010 ICFP Programming Contest is only 2 weeks away.

Monday, May 31, 2010

Correcting Towers of Hanoi Haskell Solution

I've been really having fun playing with Haskell. I found a solution via Wikipedia for the Towers of Hanoi. The solution is here http://www.kernelthread.com/projects/hanoi//html/hs.html.



This solution will not compile with ghci v6.12.1. This is the corrected solution I tested and confirmed works with ghci v6.12.1:



dohanoi :: (Num a) => a -> a -> a -> a -> [(a,a)]

dohanoi 0 _ _ _ = []

dohanoi n from to using = let m=n-1

in dohanoi m from using to ++ [(from,to)] ++ dohanoi m using to from



hanoi :: (Num a) => a -> [(a,a)]

hanoi n = dohanoi n 1 3 2