Skip to content

Instantly share code, notes, and snippets.

@stevekrenzel
Last active December 11, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stevekrenzel/4678175 to your computer and use it in GitHub Desktop.
Save stevekrenzel/4678175 to your computer and use it in GitHub Desktop.
Combinations Tree
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