Advertisement
Guest User

Untitled

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