summaryrefslogtreecommitdiff
path: root/80-89/82.hs
diff options
context:
space:
mode:
Diffstat (limited to '80-89/82.hs')
-rw-r--r--80-89/82.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/80-89/82.hs b/80-89/82.hs
new file mode 100644
index 0000000..3e8fe2e
--- /dev/null
+++ b/80-89/82.hs
@@ -0,0 +1,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