@@ -0,0 +1,1178 @@
+%22%22%22%0AImplement an algorithm to print all valid (e.g., properly opened and%0Aclosed) combinations of n-pairs of parentheses.%0AEXAMPLE:%0A  input: 3 (e.g., 3 pairs of parentheses)%0A  output: ()()(), ()(()), (())(), ((()))%0A%22%22%22%0A%0Aimport unittest%0A%0A%0Adef gen_parenthesis(count):%0A    if count == 0:%0A        return set()%0A    elif count == 1:%0A        return %7B%22()%22%7D%0A%0A    s = set()%0A    for item in gen_parenthesis(count - 1):%0A        s.add(%22(%25s)%22 %25 item)%0A        s.add(%22%25s()%22 %25 item)%0A        s.add(%22()%25s%22 %25 item)%0A%0A    return s%0A%0A%0Aclass TestGenParenthesis(unittest.TestCase):%0A    def test_gen_parenthesis_3(self):%0A        s3 = gen_parenthesis(3)%0A        self.assertEqual(5, len(s3))%0A        self.assertIn(%22()()()%22, s3)%0A        self.assertIn(%22()(())%22, s3)%0A        self.assertIn(%22(())()%22, s3)%0A        self.assertIn(%22(()())%22, s3)%0A        self.assertIn(%22((()))%22, s3)%0A%0A    def test_gen_parenthesis_1(self):%0A        s1 = gen_parenthesis(1)%0A        self.assertEqual(1, len(s1))%0A        self.assertIn(%22()%22, s1)%0A%0A    def test_gen_parenthesis_empty(self):%0A        self.assertEqual(len(gen_parenthesis(0)), 0)%0A        self.assertEqual(gen_parenthesis(0), set())%0A%0A%0Aif __name__ == %22__main__%22:%0A    unittest.main()%0A

Generate balanced parenthesis (python)