From 08fc8c1663d750199342aa36fb1727de37f23f18 Mon Sep 17 00:00:00 2001 From: Kayode Date: Tue, 6 Dec 2022 14:42:39 +0100 Subject: [PATCH] Kayode-week13. Bracket Combinations --- week13/bracket_combinations.md | 14 ++++++++++++++ week13/bracket_combinations.py | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 week13/bracket_combinations.md create mode 100644 week13/bracket_combinations.py 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