Ejemplo n.º 1
0
def combinations(list_of_items):
    """

    nPr = n! / (n_1! * n_2! * ... * n_k!)
    nPr(['s','t','a','t','i','s','t','i','c','s']) ==  50400
    :param list_of_items:
    :return: number of different combinations
    """
    numerator = factorial(len(list_of_items))  # n!
    char_counts = {}
    for item in list_of_items:
        char_counts[item] = list_of_items.count(item)
    denominator = 1
    for count in char_counts:
        denominator *= factorial(
            char_counts[count])  # n_1! * n_2! * ... * n_k!
    return numerator // denominator
Ejemplo n.º 2
0
	def test_large_factorial(self):
		result = problem20.factorial(100)
		self.assertEqual(result / int(1e155), 933L) 
Ejemplo n.º 3
0
 def test_large_factorial(self):
     result = problem20.factorial(100)
     self.assertEqual(result / int(1e155), 933L)
Ejemplo n.º 4
0
	def test_small_factorial(self):
		result = problem20.factorial(10)
		self.assertEqual(result, 3628800)
Ejemplo n.º 5
0
 def test_small_factorial(self):
     result = problem20.factorial(10)
     self.assertEqual(result, 3628800)