Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- successors' :: Problem a => a -> [Traced a]
- successors' startRiver = concat (map cycleDetect (nub (successors'' [startRiver] [] [Traced startRiver []])))
- --Since we want to generate all possible states, we have to generate past the solution.
- --However, this means that the solution is not the 'current' part of Traced, though we want that.
- --cycleDetect finds instances of Traced whose trace contains a solution,
- --then cuts back to that solution, maintaining the original Traced in the process.
- cycleDetect :: Problem a => Traced a -> [Traced a]
- cycleDetect (Traced x xs) |elem True (map a xs) = [c,Traced (head b) (tail b)]
- |otherwise = [c]
- where a = (\x -> isSolution x)
- b = dropWhile (\x -> not(isSolution x)) xs
- c = Traced x xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement