haskell-homework/lib/Homework/Ch01/Hanoi.hs

27 lines
718 B
Haskell
Raw Normal View History

2021-10-01 00:04:16 +00:00
module Homework.Ch01.Hanoi where
import qualified Data.HashMap.Strict as HashMap
newtype Peg = Peg ()
data Move = Move {moveFrom :: String, moveTo :: String} deriving (Eq, Show)
data Disc = Disc {discSize :: Int}
hanoi :: Int -> String -> String -> String -> Either String [Move]
hanoi numDisks pegLabelA pegLabelB pegLabelC =
let _pegs =
HashMap.fromList
[ (pegLabelA, fillPegWithDiscs),
(pegLabelB, []),
(pegLabelC, [])
]
in Right
[ Move "a" "c",
Move "a" "b",
Move "c" "b"
]
where
fillPegWithDiscs :: [Disc]
fillPegWithDiscs = Disc <$> [1 .. numDisks] -- start here: make sure this is initialized correctly