Total Outfit Combinations
You are given a wardrobe containing pants, shirts, and hats. Along with the total number of each type of clothing (pants, shirts, and hats), you are also provided with the number of unique types of each clothing item.
Each item of clothing can be combined with any other items to form an outfit. An outfit consists of one pair of pants, one shirt, and optionally one hat.
Write a function count_unique_outfits to determine the total number of unique outfit combinations you can create, including outfits with and without hats.
Pythondef count_unique_outfits(total_pants: int, unique_pants: int,
total_shirts: int, unique_shirts: int,
total_hats: int, unique_hats: int) -> int:
pass
Input:
total_pants(int): The total number of pants in the wardrobe. (1 ≤total_pants≤ 1000)unique_pants(int): The number of unique types of pants. (1 ≤unique_pants≤total_pants)total_shirts(int): The total number of shirts in the wardrobe. (1 ≤total_shirts≤ 1000)unique_shirts(int): The number of unique types of shirts. (1 ≤unique_shirts≤total_shirts)total_hats(int): The total number of hats in the wardrobe. (1 ≤total_hats≤ 1000)unique_hats(int): The number of unique types of hats. (1 ≤unique_hats≤total_hats)
Output:
- Returns an integer representing the total number of unique outfit combinations, including outfits with and without hats.
Example
Pythoncount_unique_outfits(2, 1, 1, 1, 3, 2) # returns 3
Given 2 identical pants, 1 unique shirt, and 3 hats (2 unique types), the are 18 unique outfit combinations. We can visualize it as follows:
- You have 2 red pants
- You have 1 blue shirt
- You have 2 white hats and 1 black hat
The unique outfits available to you:
- red pants + blue shirt + no hat
- red pants + blue shirt + white hat
- red pants + blue shirt + black hat
Thus, you can create 3 unique outfits based on what you have in your wardrobe.
To determine how many unique outfits you can create, consider that each outfit consists of a pair of pants, a shirt, and optionally a hat.
Every unique pair of pants can be combined with every unique shirt. To find the number of these basic combinations, simply multiply the number of unique pants by the number of unique shirts.
Each of these pants/shirt combinations can be completed with or without a hat. Since the hat is optional, you have one more choice (no hat) plus the number of unique hats you have. So, for every basic combination, you have 1 + unique_hats options (one for not wearing a hat and one for each unique hat).
The total number of unique outfits is calculated as:
Pythondef count_unique_outfits(total_pants: int, unique_pants: int,
total_shirts: int, unique_shirts: int,
total_hats: int, unique_hats: int) -> int:
unique_outfits = unique_pants * unique_shirts * (1 + unique_hats)
return unique_outfits
The total number of pants, shirts and hats are actually irrelevant here. You might have been compelled to use the additional information available to you but that may have confused you instead. Part of solving a real-world problem with code is being able to sieve out the necessary information from the sea of information available.
In practice, you'll be able to remove the total_pants, total_shirts and total_hats parameters from the function.
Pythondef count_unique_outfits(unique_pants: int,
unique_shirts: int,
unique_hats: int) -> int:
pass
def count_unique_outfits(total_pants: int, unique_pants: int, total_shirts: int, unique_shirts: int, total_hats: int, unique_hats: int) -> int: """ Number of unique outfits can simply be defined by (unique_pants_choose_1unique_shirts_choose_1unique_hats_choose_1) + (unique_pants_choose_1unique_shirts_choose_1) # Not wearing a hat n_choose_k is n """ res = (unique_pantsunique_shirtsunique_hats) + (unique_pantsunique_shirts) return res print(count_unique_outfits(2, 1, 1, 1, 3, 2))