Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bfsaux :: (Ord a) => Set.Set a -> Set.Set a -> Int -> (a -> Set.Set a) -> a -> Maybe Int
- bfsaux closed opened current neighbours target
- | opened == Set.empty = Nothing
- | Set.member target opened = Just current
- | otherwise = bfsaux newclosed newopened (current + 1) neighbours target
- where
- newclosed = Set.union closed opened
- newopened = Set.difference (Set.unions $ Set.toList $ Set.map neighbours opened) closed
- -- neighbours function, start, target
- bfs :: (Ord a) => (a -> Set.Set a) -> a -> a -> Maybe Int
- bfs neighbours start target = bfsaux Set.empty (Set.singleton start) 0 neighbours target
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement