[ create a new paste ] login | about

Link: http://codepad.org/xN63Nmnn    [ raw code | fork ]

mariuss - Haskell, pasted on Mar 26:
1
2
3
4
5
6
7
8
9
10
11
catalan :: Int -> [String]
catalan n = cata "" n 0 0 

cata ::  String -> Int -> Int -> Int -> [String]
cata s n o c
            | c==n && o==n = [s]
            | otherwise = let
                            ss1 = if o < n then cata (s ++ "(") n (o + 1) c else []
                            ss2 = if o > c then cata (s ++ ")") n o (c + 1) else []
                          in
                            ss1 ++ ss2


Create a new paste based on this one


Comments: