Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions week13/bracket_combinations.md
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions week13/bracket_combinations.py
Original file line number Diff line number Diff line change
@@ -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())