List rooted trees: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: Simplified the Data.Tree version a little)
m (→‎{{header|Haskell}}: Named a couple of anonymous functions)
Line 571: Line 571:
bagPatterns n =
bagPatterns n =
nub $
nub $
foldTree
foldTree asBrackets
. foldTree depthSorted
(\_ xs -> '(' : (concat xs <> ")"))
. foldTree
( const (Node <$> length <*> sortOn rootLabel)
)
. treeFromParentIndices
. treeFromParentIndices
<$> parentIndexPermutations n
<$> parentIndexPermutations n
Line 584: Line 581:


----------------------- DEFINITIONS ----------------------
----------------------- DEFINITIONS ----------------------

asBrackets :: a -> [String] -> String
asBrackets = const (('(' :) . (<> ")") . concat)

depthSorted :: a -> [Tree Int] -> Tree Int
depthSorted = const (Node <$> length <*> sortOn rootLabel)


parentIndexPermutations :: Int -> [[Int]]
parentIndexPermutations :: Int -> [[Int]]