<jupyter_start><jupyter_text>Socks from a BoxLet's say we have a box filled with socks: three pairs each of white, gray, and black socks (i.e. six socks of each of the three colors, for eighteen socks in total). In each of the questions below, we draw socks randomly from the box without replacement. Note that a pair of matching socks is simply two of the same color: each sock will fit a foot of either handedness – uh, footedness. (Socks do not have chirality, for those into mathematical terms.)Input your answers as fractions or as decimals with at least four digits of precision.<jupyter_code># library imports
#import pandas as pd
#from math import factorial as fact<jupyter_output><empty_output><jupyter_text>Question 1Let's say we draw two socks from the box. What is the probability that we draw a matching pair?<jupyter_code># statement of problem:
# 3 colors (white = w; grey = g; black = b)
# 3x2 socks of each color
# 3x2x3 = 18 socks total
# probability of 1 first white sock = pw1
pw1 = 6/18 # there are 6 white socks out of 18 in total
pw1
# no replacement
# probability of 1 second white sock = pw2
pw2 = (6-1)/(18-1) # after the first draw, there are now 5 white socks out of a total of 17
# pw2 = 5/17
pw2
# probability (P2W) of 1w AND 1w = pw1 * pw2
# pw1 = 6/18 = 1/3
# pw2 = 5/17
# P2W = 1/3 * 5/17
P2W = pw1 * pw2
P2W
# probability (P2Socks) of 2w OR 2b OR 2g = P2W + P2B + P2G = 3 * P2W
P2Socks = 3 * P2W
print('The probability of drawing a matching pair is: '+ str(P2Socks))<jupyter_output>The probability of drawing a matching pair is: 0.29411764705882354<jupyter_text>Question 2What if we draw three socks from the box instead. What is the probability that we draw a matching pair? (Having all three socks be the same color also counts as having a matching pair.)<jupyter_code># because colors can be permutated, we can state that if we draw three socks, we can draw (where 'c' is color):
# favourableArray1 = [[c1, c1, c1],[c1, c1, c2],[c1, c1, c3]]
# favourableArray2 = [[c2, c1, c1],[c1,c2,c1]]
# favourableArray3 = [[c3, c1, c1],[c1,c3,c1]]
# in order to get two or more socks of the same color
# As there are three colors we can have 3 * favourableArray
# There are a total of 3*3*3 totals possible combinations = 27, of which 21 are favourable and 6 are not
# prob of c1c2c3 in this order
Pc1c2c3 = 6/18 * 6/17 * 6/16
Pc1c2c3
# Pc1c2c3 in any order (6 cases)
PanyOrder = 6 * Pc1c2c3
PanyOrder
# probability of a pair
PPair = 1 - PanyOrder
PPair<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0817384370015949, 'fraction_numerical': 0.06060606060606061, 'mean_word_length': 4.2053941908713695, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '483275', 'license': 'MIT', 'n_tokens_mistral': 933, 'n_tokens_neox': 851, 'n_words': 396, 'path': 'term2/lesson2_statsProgEx/SocksFromABox.ipynb', 'repo_name': 'Zabamund/datasci-nano', 'size': '2508'}