Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Starting in the top left corner of a 2×2 grid, and only being able
- to move to the right and down, there are exactly 6 routes to the bottom right corner.
- '''
- # The solution is a string made up with 40 letters, but we have to use
- # exactly 20 '0's ---> right move and exactly 20 '1's ---> down move
- # So, we have n = 40 letters and two teams with n1 = 20 letters and n2 = 20
- # To produce all the combinations, I use the formula: combinations = n! / (n1! * n2!),
- # where n = n1 + n2
- def factorial(n):
- if n < 0 or n != int(n):
- print("Error using the factorial function.")
- return -1000
- elif n == 0 or n == 1:
- return 1
- else:
- fact = list()
- fact.append(1)
- for i in range(1, n+1):
- fact.append(i * fact[i-1])
- return fact[n]
- def produceCombinationsOfTwoTeams(n, n1, n2):
- if n == n1 + n2 and n == int(n) and n1 == int(n1) and n2 == int(n2) and n > 0 and n1 > 0 and n2 > 0:
- return factorial(n) / factorial(n1) / factorial(n2)
- else:
- print("Error using the fucntion produceCombinationsOfTwoTeams")
- return -1000
- # MAIN FUNCTION
- print(produceCombinationsOfTwoTeams(40, 20, 20))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement