Commits

Rhys !  committed 6fa14f4 Draft

remove old problem files

  • Participants
  • Parent commits 0730391

Comments (0)

Files changed (2)

File bucharest.hs

-import Data.Function
-
-import Search
-
-data Location = Location { name :: String
-                         , sld :: Integer
-                         , paths :: [(Location, Integer)]}
-
-instance Eq Location where
-    (==) = (==) `on` name
-
-instance Show Location where
-    show = name
-
-arad = Location "Arad" 366 [(sibiu, 140)]
-sibiu = Location "Sibiu" 253 [(arad, 140), (fagaras, 99), (rimnicuVilcea, 80)]
-fagaras = Location "Fagaras" 178 [(bucharest, 211)]
-rimnicuVilcea = Location "Rimnicu Vilcea" 193 [(sibiu, 80), (pitesti, 97)]
-pitesti = Location "Pitesti" 98 [(bucharest, 101)]
-bucharest = Location "Bucharest" 0 [(fagaras, 211), (pitesti, 101)]
-
-expand :: Path Integer Location -> [Path Integer Location]
-expand h = fmap travel $ paths $ stateAt h where
-    travel :: (Location, Integer) -> Path Integer Location
-    travel = uncurry $ flip $ Step h
-
-solve method = search method expand (== bucharest) arad

File jugs.hs

-import Data.Tuple
-
-import Search
-
-data Action s = Action { name :: String
-                       , precondition :: (s -> Bool)
-                       , act :: (s -> s) }
-
-instance Show (Action s) where
-    show = name
-
-validActions :: [Action s] -> s -> [Action s]
-validActions actions state = filter (flip ($) state . precondition) actions
-
-validExpansions :: [Action s] -> History String s -> [History String s]
-validExpansions actions h = fmap toHistory $ validActions actions $ stateAt h where
-    toHistory action = Step h (name action) (act action (stateAt h))
-
-mapFst f (a, b) = (f a, b)
-mapSnd f (a, b) = (a, f b)
-mapBoth f g (a, b) = (f a, g b)
-
-pour l (a, b) = (a - d, b + d) where
-    d = min a (l - b)
-
-actions = [ Action { name = "fill3"
-                   , precondition = (< 3) . fst
-                   , act = mapFst (const 3) }
-          , Action { name = "empty3"
-                   , precondition = (> 0) . fst
-                   , act = mapFst (const 0) }
-          , Action { name = "fill5"
-                   , precondition = (< 5) . snd
-                   , act = mapSnd (const 5) }
-          , Action { name = "empty5"
-                   , precondition = (> 0) . snd
-                   , act = mapSnd (const 0) }
-          , Action { name = "pour35"
-                   , precondition = uncurry (&&) . mapBoth (> 0) (< 5)
-                   , act = pour 5 }
-          , Action { name = "pour53"
-                   , precondition = uncurry (&&) . mapBoth (< 3) (> 0)
-                   , act = swap . (pour 3) . swap } ]
-
-solveJugs aim = search breadthFirst (validExpansions actions) (== aim) (0, 0)