This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.PQueue.Prio.Min as PQ | |
import qualified Data.HashSet as Set | |
import qualified Data.HashMap.Strict as Map | |
import Data.Hashable (Hashable) | |
import Data.List (foldl') | |
import Data.Maybe (fromJust) | |
astarSearch :: (Eq a, Hashable a) => a -> (a -> Bool) -> (a -> [(a, Int)]) -> (a -> Int) -> Maybe (Int, [a]) | |
astarSearch startNode isGoalNode nextNodeFn heuristic = | |
astar (PQ.singleton (heuristic startNode) (startNode, 0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Maps each element to a 1, then sums up all the elements | |
len :: [a] -> Integer | |
len = sum . map (\_ -> 1) | |
-- Adds up all the heads (recursively) until the list is empty | |
len' :: [a] -> Integer | |
len' [] = 0 | |
len' (_:xs) = 1 + len' xs | |
-- Extract into a fold using this technique: [ [] := v, (:) := f ] |