#1- What is the probability of rolling a sum of 12 on three rolls of six-sided dice? Express your answer as a decimal number only. Show your R code.

dice_rolls <- expand.grid(1:6, 1:6, 1:6)
dice_rolls_matrix <- as.matrix(dice_rolls)
roll_12 <- dice_rolls[rowSums(dice_rolls_matrix)==12,]
prob_roll_12 <- nrow(roll_12)/(6^3)
prob_roll_12
## [1] 0.1157407
result <- prob_roll_12 * 100 
result 
## [1] 11.57407

2-

data <- c("200","200","100","200","200","300","100","200","100","100")
m <- matrix(data, nrow = 5, ncol = 2)
m
##      [,1]  [,2] 
## [1,] "200" "300"
## [2,] "200" "100"
## [3,] "100" "200"
## [4,] "200" "100"
## [5,] "200" "100"
dimnames(m) <- list(c("Aparment","Dorm","With parents","fraternity","other"), c("male","female"))
m
##              male  female
## Aparment     "200" "300" 
## Dorm         "200" "100" 
## With parents "100" "200" 
## fraternity   "200" "100" 
## other        "200" "100"
#probability of females 
Prob_of_female <- 100 / 1700 
Prob_of_female
## [1] 0.05882353
#Probability of mens 
Prob_of_male <- 200 / 1700 
Prob_of_male
## [1] 0.1176471
#final probabilities 
final_prob <- Prob_of_female + Prob_of_male
final_prob
## [1] 0.1764706

#3 Two cards are drawn without replacement from a standard deck of 52 playing cards.
What is the probability of choosing a diamond for the second card drawn, if the first
card, drawn without replacement, was a diamond?
Express your answer as a decimal number only. Show your R code.

#deck has 52 cards (one is already out)

deck <- 52-1 

#they are a total of 13 cards for symbol (1 diamond is out)

get_diamond <- 12/deck
get_diamond
## [1] 0.2352941

#4 - A coordinator will select 10 songs from a list of 20 songs to compose an event’s
musical entertainment lineup. How many different lineups are possible?
Show your R code.

#Combination result 
?choose

choose(20,10) 
## [1] 184756
#Permutation result
factorial(20) / (factorial(20 - 10))
## [1] 670442572800

#5You are ordering a new home theater system that consists of a TV, surround sound
system, and DVD player. You can choose from 20 different TVs, 20 types of surround
sound systems, and 18 types of DVD players. How many different home theater
systems can you build?
#combination

Tv <- 20 
Ss <- 20 
Dvd <- 18 

total_systems <- Tv * Ss * Dvd
total_systems
## [1] 7200

#6 A doctor visits her patients during morning rounds. In how many ways can the doctor visit 10 patients during the morning rounds?
Show your R code.

factorial(10)
## [1] 3628800

#7 If a coin is tossed 7 times, and then a standard six-sided die is rolled 3 times, and finally
a group of four cards are drawn from a standard deck of 52 cards without replacement,
how many different outcomes are possible?
Show your R code.

coin <- 2^7
dice <- 6^3 
#cards <- choose(52,4) not correct 
perm_without_replacement <- function(n, r){
  return(factorial(n)/factorial(n - r))
}
cards2 <- perm_without_replacement(53,4) 
outcomes <- coin * dice * cards2
outcomes
## [1] 194304614400

#8 In how many ways may a party of four women and four men be seated at a round table
if the women and men are to occupy alternate seats.
Show your R code.

mens <- factorial(4-1)
women <- factorial(4)
seats <- mens * women 
seats 
## [1] 144

#9 An opioid urinalysis test is 95% sensitive for a 30-day period, meaning that if a person
has actually used opioids within 30 days, they will test positive 95% of the time P( + |
User) =.95. The same test is 99% specific, meaning that if they did not use opioids within
30 days, they will test negative P( - | Not User) = .99. Assume that 3% of the population
are users. Then what is the probability that a person who tests positive is actually a user
P(User | +)?

# user 
u <- 0.03
# non user 
nu <- 0.97
# user and positive
up <- 0.95
#non user and postive
nup <- 0.01

#Bayes 
P_up <- ((u * up)/((up*u)+(nu*nup)))
P_up
## [1] 0.7460733

#10 You have a hat in which there are three pancakes. One is golden on both sides, one is
brown on both sides, and one is golden on one side and brown on the other. You
withdraw one pancake and see that one side is brown. What is the probability that the
other side is brown? Explain.

gb <- 1/3 
bb <- 1/3
bg <- 1/3 

#since you know that 1 side is brown you dont need to use gb beccause is not posible. 

result <- 1/3 + 1/3 
result
## [1] 0.6666667