mirror of
https://codeberg.org/JasterV/word-ladder.hs.git
synced 2026-04-26 18:10:06 +00:00
finish implementing bfsSearch
This commit is contained in:
parent
f866bc2025
commit
827797d6b6
1 changed files with 6 additions and 1 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
|
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
|
||||||
|
|
||||||
{-# HLINT ignore "Use map once" #-}
|
{-# HLINT ignore "Use map once" #-}
|
||||||
|
|
||||||
module Graph
|
module Graph
|
||||||
( DiGraph,
|
( DiGraph,
|
||||||
hasNode,
|
hasNode,
|
||||||
|
|
@ -84,7 +85,11 @@ bfsSearch initialGraph start end
|
||||||
Success preds -> Just (findSolution preds)
|
Success preds -> Just (findSolution preds)
|
||||||
where
|
where
|
||||||
findSolution :: DiGraph a -> [a]
|
findSolution :: DiGraph a -> [a]
|
||||||
findSolution _graph = undefined
|
findSolution predecessors = L.reverse (aux end)
|
||||||
|
where
|
||||||
|
aux node = case children node predecessors of
|
||||||
|
[] -> [node]
|
||||||
|
(x : _) -> node : aux x
|
||||||
|
|
||||||
bfsSearch' :: SearchState a -> SearchResult a
|
bfsSearch' :: SearchState a -> SearchResult a
|
||||||
bfsSearch' ([], _, _) = Unsuccessful
|
bfsSearch' ([], _, _) = Unsuccessful
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue