Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. import Control.Monad
  2. import Text.Printf
  3.  
  4. parenthsCombinations :: Word -> [String]
  5. parenthsCombinations 0 = [""]
  6. parenthsCombinations n =
  7. concatMap (uncurry $ liftM2 $ printf "(%s)%s") $
  8. zip combinations (reverse combinations)
  9. where combinations = map parenthsCombinations [n - 1, n - 2 .. 0]
  10.  
  11. main = readLn >>= putStr . concatMap (++ "\n") . parenthsCombinations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement