data_605_hw6

Question 1

A bag contains 5 green and 7 red jellybeans. How many ways can 5 jellybeans be withdrawn from the bag so that the number of green ones withdrawn will be less than 2?

Solution: The answer is 6. “Less than 2” means that it can be either 1 or 0 green jellybean chosen from the bag. If we are going to pick 5 out in random from the bag and there’s only 1 green jellybean, that green jellybean can be chosen in any order (or position), i.e. 1st, 2nd, 3rd, 4th or 5th. Therefore, we would have 5 combinations if there’s only 1 green jellybean chosen. In addition, we could have chosen 0 green jellybean. Together, we end up having 6 ways of satisfying the requirement.

Question 2

A certain congressional committee consists of 14 senators and 13 representatives. How many ways can a subcommittee of 5 be formed if at least 4 of the members must be representatives?

sen <- 14
rep <- 13
subcom <- 5
scenarios <- c(4, 5)
tempList <- vector(mode = "list", length = length(scenarios))

for(i in 1:length(scenarios)){
    
    tempList[[i]] = choose(rep, scenarios[i]) * choose(sen, subcom - scenarios[i])    
    
}

solution = reduce(tempList, `+`)

print(paste0(glue("There are ", {solution}, " ways of chooseing at least 4 out of ", {rep}, " representatives and 1 or 0 out of ", {sen}, " senators to form a 5-member subcommittee")))
## [1] "There are 11297 ways of chooseing at least 4 out of 13 representatives and 1 or 0 out of 14 senators to form a 5-member subcommittee"

Solution: To form a 5-member subcommittee and have at least 4 representatives, that means we would have chosen either 4 or 5 representatives out of 13. There are only 2 scenarios, i.e. either 4 representatives and 1 senator or 5 representatives and 0 senators. We need to sum up the number of combinations for each of these two scenarios. The solution is 11297.

Question 3

If a coin is tossed 5 times, and then a standard six-sided die is rolled 2 times, and finally a group of three cards are drawn from a standard deck of 52 cards without replacement, how many different outcomes are possible?

solution <- nrow(gtools::combinations(2, 5, repeats.allowed = TRUE)) *
nrow(gtools::combinations(6, 2, repeats.allowed = TRUE)) *
nrow(gtools::combinations(52, 3, repeats.allowed = TRUE))

print(glue("Assuming that order does not matter, e.g. when we flip a coin 3 times, Tail-Head-Tail and Tail-Tail-Head would be considered the same outcome, then there are ", {solution}, " different outcomes possible in this situation"))
## Assuming that order does not matter, e.g. when we flip a coin 3 times, Tail-Head-Tail and Tail-Tail-Head would be considered the same outcome, then there are 3125304 different outcomes possible in this situation

Question 4

3 cards are drawn from a standard deck without replacement. What is the probability that at least one of the cards drawn is a 3? Express your answer as a fraction or a decimal number rounded to four decimal places.

first_draw_not_three = 48 / 52
second_draw_not_three = 47 / 51
third_draw_not_three = 46 / 50

at_least_one_three = 1 - first_draw_not_three * second_draw_not_three * third_draw_not_three
print(glue("The probability that at least one of the cards drawn from a standard deck without replacement is a 3 is approximately ", round({at_least_one_three}, 4)))
## The probability that at least one of the cards drawn from a standard deck without replacement is a 3 is approximately 0.2174

Question 5

Lorenzo is picking out some movies to rent, and he is primarily interested in documentaries and mysteries. He has narrowed down his selections to 17 documentaries and 14 mysteries.

Step 1

How many different combinations of 5 movies can he rent?

random_5_movies = choose(31, 5)
print(glue("There are ", {random_5_movies}, " different combinations of 5 movies that he can rent out of total of 31 (17 + 14) movies"))
## There are 169911 different combinations of 5 movies that he can rent out of total of 31 (17 + 14) movies

Step 2

How many different combinations of 5 movies can he rent if he wants at least one mystery?

all_docu_movies = choose(17, 5)
print(glue("There are ", {random_5_movies} - {all_docu_movies}, " different combinations of 5 movies that he can rent if he wants at least one mystery"))
## There are 163723 different combinations of 5 movies that he can rent if he wants at least one mystery

Question 6

In choosing what music to play at a charity fund raising event, Cory needs to have an equal number of symphonies from Brahms, Haydn, and Mendelssohn. If he is setting up a schedule of the 9 symphonies to be played, and he has 4 Brahms, 104 Haydn, and 17 Mendelssohn symphonies from which to choose, how many different schedules are possible? Express your answer in scientific notation rounding to the hundredths place.

b <- choose(4, 3)
h <- choose(104, 3)
m <- choose(17, 3)
solution = b * h * m
print(glue("There are ", {formatC(solution, format = "e", digits = 2)}, " different schedules possible"))
## There are 4.95e+08 different schedules possible

Question 7

An English teacher needs to pick 13 books to put on his reading list for the next school year, and he needs to plan the order in which they should be read. He has narrowed down his choices to 6 novels, 6 plays, 7 poetry books, and 5 nonfiction books.

Step 1

If he wants to include no more than 4 nonfiction books, how many different reading schedules are possible? Express your answer in scientific notation rounding to the hundredths place.

# Computation is either too slow or never return any result due to limited memory, use factorial() instead
# solution <- nrow(gtools::permutations(5, 4)) * nrow(gtools::permutations(19, 9)) +
#     nrow(gtools::permutations(5, 3)) * nrow(gtools::permutations(19, 10)) +
#     nrow(gtools::permutations(5, 2)) * nrow(gtools::permutations(19, 11)) +
#     nrow(gtools::permutations(5, 1)) * nrow(gtools::permutations(19, 12)) +
#     nrow(gtools::permutations(19, 13))

solution2 <- (factorial(5) / factorial(1) * factorial(19) / factorial(10)) +
    (factorial(5) / factorial(2) * factorial(19) / factorial(9)) +
    (factorial(5) / factorial(3) * factorial(19) / factorial(8)) +
    (factorial(5) / factorial(4) * factorial(19) / factorial(7)) +
    (factorial(19) / factorial(6))

print(glue("Since order matters in this case, we need to apply the permutation formula to get the answer. There are ", {formatC(solution2, format = "e", digits = 2)}, " different reading schedules possible"))
## Since order matters in this case, we need to apply the permutation formula to get the answer. There are 3.74e+14 different reading schedules possible

Step 2

If he wants to include all 6 plays, how many different reading schedules are possible? Express your answer in scientific notation rounding to the hundredths place.

# Computation is either too slow or never return any result due to limited memory, use factorial() instead
# nrow(gtools::permutations(6, 6)) * nrow(gtools::permutations(18, 7))
solution3 <- (factorial(6) / factorial(0) * factorial(18) / factorial(11))

print(glue("Since order still matters in this case, and he wants to include all 6 plays in the reading schedule, the total number of available reading schedules is ", {formatC(solution3, format = "e", digits = 2)}))
## Since order still matters in this case, and he wants to include all 6 plays in the reading schedule, the total number of available reading schedules is 1.15e+11

Question 8

Zane is planting trees along his driveway, and he has 5 sycamores and 5 cypress trees to plant in one row. What is the probability that he randomly plants the trees so that all 5 sycamores are next to each other and all 5 cypress trees are next to each other? Express your answer as a fraction or a decimal number rounded to four decimal places.

total_choices = choose(10, 5)
the_outcome_we_care_about = 1
types_of_trees = 2

print(glue("The probability of planting the trees next to each other with the same kind is approximately ", {round(types_of_trees * the_outcome_we_care_about / total_choices, 4)}, ". Consider you have to pick 5 of the same kind out of 10 trees in random. That's a simple combination formula, i.e. choose(10, 5) but with only one desireable outcome, i.e. SSSSS or CCCCC. Now, after you finish picking 5 of the same kind out of 10, i.e. 1 / choose(10, 5), the remaining 5 would also be the same kind. Therefore, we just need to care about finding the probability of picking 5 of the same kind out of 10 in random. Since there are two types of trees, we would add that probability twice. In this case, the probability would be 1 / choose(10, 5) + 1 / choose(10, 5)."))
## The probability of planting the trees next to each other with the same kind is approximately 0.0079. Consider you have to pick 5 of the same kind out of 10 trees in random. That's a simple combination formula, i.e. choose(10, 5) but with only one desireable outcome, i.e. SSSSS or CCCCC. Now, after you finish picking 5 of the same kind out of 10, i.e. 1 / choose(10, 5), the remaining 5 would also be the same kind. Therefore, we just need to care about finding the probability of picking 5 of the same kind out of 10 in random. Since there are two types of trees, we would add that probability twice. In this case, the probability would be 1 / choose(10, 5) + 1 / choose(10, 5).

Question 9

If you draw a queen or lower from a standard deck of cards, I will pay you 4 dollars. If not, you pay me 16 dollars. (Aces are considered the highest card in the deck.)

Step 1

Find the expected value of the proposition. Round your answer to two decimal places. Losses must be expressed as negative values.

expected_value = 4 * (44 / 52) - 16 * (8 / 52)

print(glue("The expected value of this proposition is equal to $", round({expected_value}, 2)))
## The expected value of this proposition is equal to $0.92

Step 2

If you played this game 833 times how much would you expect to win or lose? Round your answer to two decimal places. Losses must be expressed as negative values.

games = 833

print(glue("After playing it ", {games}, " times, the expected outcome would be $", {round(games * expected_value, 2)}))
## After playing it 833 times, the expected outcome would be $768.92