diff --git a/week13/bracket_combinations.md b/week13/bracket_combinations.md new file mode 100644 index 0000000..d28d708 --- /dev/null +++ b/week13/bracket_combinations.md @@ -0,0 +1,14 @@ +--- +Author: Kayode +--- + +Bracket Combinations + +Have the function BracketCombinations(num) read num which will be an integer greater than or equal to zero, and return the number of valid combinations that can be formed with num pairs of parentheses. For example, if the input is 3, then the possible combinations of 3 pairs of parenthesis, namely: ()()(), are ()()(), ()(()), (())(), ((())), and (()()). There are 5 total combinations when the input is 3, so your program should return 5. + +Examples +Input: 3 +Output: 5 + +Input: 2 +Output: 2 \ No newline at end of file diff --git a/week13/bracket_combinations.py b/week13/bracket_combinations.py new file mode 100644 index 0000000..b411b09 --- /dev/null +++ b/week13/bracket_combinations.py @@ -0,0 +1,15 @@ +import math + +def bracketcombinatins(num): + if num == 0 or num == 1: + return 1 + + a= math.factorial((2*num)) + b= math.factorial((num + 1)) + c= math.factorial(num) + + ans= a / (b * c) + return int(ans) + + +print(bracketcombinatins()) \ No newline at end of file