Last active
December 11, 2015 23:39
-
-
Save stevekrenzel/4678175 to your computer and use it in GitHub Desktop.
Combinations Tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
import Data.Tree | |
combinationsTree xs = unfoldTree next ([], xs) | |
where next (path, xs) = (path, map (appendTo path . splitAt 1) $ init $ tails xs) | |
appendTo path (x, ys) = (path ++ x, ys) | |
depth 0 node = Node{rootLabel=(rootLabel node), subForest=[]} | |
depth n node = node{subForest=(map (depth (n - 1)) (subForest node))} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment