summaryrefslogblamecommitdiff
path: root/80-89/82.hs
blob: 3e8fe2e0d074024caf577fdfd0f9737cdf408d3b (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                                                     
import Data.List (partition)

cycle' :: Eq a => a -> [(a, a)] -> [[a]]

cycle' s edges = map reverse $ cycle'' s edges [s] False
    where
        cycle'' u edges path f
          | f && u == s = [path]
          | otherwise =
                do  let (vs, edges') = partition ((== u) . fst) edges
                    (_, v) <- vs
                    cycle'' v edges' (v:path) True