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
def test_large_factorial(self): result = problem20.factorial(100) self.assertEqual(result / int(1e155), 933L)
def test_small_factorial(self): result = problem20.factorial(10) self.assertEqual(result, 3628800)