round(1/540,4)
## [1] 0.0019
toppings <- c('A', 'C')
meats <- c('E','T')
dressings <- c('F','V')
expand.grid(x=toppings, y=meats, z=dressings)
## x y z
## 1 A E F
## 2 C E F
## 3 A T F
## 4 C T F
## 5 A E V
## 6 C E V
## 7 A T V
## 8 C T V
deckOfCards <- CombPairs(x=c(2:10,'A','J','Q','K'), y=c('H', 'C','S','D'))
names(deckOfCards) <- c('value', 'suit')
total <- nrow(deckOfCards)
valid <- nrow(deckOfCards[deckOfCards$value %in% c(2:10) & deckOfCards$suit == 'H',])
round(valid/total, 4)
## [1] 0.1731
dice <- CombPairs(x=1:6, y=1:6)
names(dice) <- c('die1', 'die2')
total <- nrow(dice)
valid <- nrow(dice[dice$die1 + dice$die2 < 6, ])
round(valid/total, 4)
## [1] 0.2778
round(sum(233, 159, 102, 220, 250)/2001, 4)
## [1] 0.4818
card1 <- nrow(deckOfCards[deckOfCards$suit == 'C',])
card2 <- nrow(deckOfCards[deckOfCards$suit %in% c('C','S'),])
card3 <- nrow(deckOfCards[deckOfCards$value %in% c('A','J','Q','K'),])
round((card1+card2+card3)/(nrow(deckOfCards)*3), 4)
## [1] 0.3526
round(13/51, 4)
## [1] 0.2549
round(13/52*12/51, 4)
## [1] 0.0588
total <- sum(12, 19, 12, 7, 12, 15, 4, 4)
firstPick <- 4 / total
secondPick <- 12 / (total-1)
round(firstPick*secondPick, 4)
## [1] 0.0067
maleNoGrad <- 141
maleGrad <- 52
femaleGrad <- 50
femaleNoGrad <- 57
round(maleGrad/(maleNoGrad+maleGrad),4)
## [1] 0.2694
round(maleGrad/(maleGrad+femaleGrad),4)
## [1] 0.5098
sprintf('There are %s value meal packages', 6*5*3)
## [1] "There are 90 value meal packages"
sprintf('There are %s different orders to visit the patients.', factorial(5))
## [1] "There are 120 different orders to visit the patients."
Assuming order doesn’t matter
sprintf('%s different sets of songs can be chosen', choose(8,5))
## [1] "56 different sets of songs can be chosen"
factorial(9)/(factorial(3)*factorial(5)*factorial(1))
## [1] 504
sprintf('There are %s different combinations of toppings', choose(14, 6))
## [1] "There are 3003 different combinations of toppings"
sprintf('There are %s different combinations of 3 card hands', 52*51*50)
## [1] "There are 132600 different combinations of 3 card hands"
sprintf('There are %s different combinations of setups', 12*9*5)
## [1] "There are 540 different combinations of setups"
sprintf('There are %s different possible passwords', 26*25*24*23*22*5*4*3)
## [1] "There are 473616000 different possible passwords"
perm <- function(n, r){ factorial(n) / factorial(n-r)}
perm(9,4)
## [1] 3024
choose(11, 8)
## [1] 165
perm(12,8) / choose(12, 4)
## [1] 40320
sprintf('There are %s different permutations of cabinets.', perm(13, 7))
## [1] "There are 8648640 different permutations of cabinets."
Assuming capital P and lowercase p are different
sprintf('There are %s different permutations of Population.', factorial(10)/factorial(2))
## [1] "There are 1814400 different permutations of Population."
expectedValues <- data.frame(5:9, c(0.1,0.2,0.3,0.2,0.2))
names(expectedValues) <- c('x', 'pOfX')
E <- sum(expectedValues$x*expectedValues$pOfX)
round(E, 1)
## [1] 7.2
V <- sum((expectedValues$x - E)^2*expectedValues$pOfX)
round(V,1)
## [1] 1.6
SD <- sqrt(V)
round(SD,1)
## [1] 1.2
round(pnorm(9, E, SD), 1)
## [1] 0.9
round(1-pnorm(7, E, SD), 1)
## [1] 0.6
success <- dbinom(3, size=3, prob=188/376)
E <- success*23 - (1-success)*4
round(E,2)
## [1] -0.62
sprintf('I would expected to end up with %s dollars', E*994)
## [1] "I would expected to end up with -621.25 dollars"
success <- pbinom(8, 11, 0.5)
E <- success*1-(1-success)*7
round(E,2)
## [1] 0.74
sprintf('I would expected to end up with %s dollars', E*615)
## [1] "I would expected to end up with 454.04296875 dollars"
success <- (13*12)/(52*51)
E <- success*583 - (1-success)*35
round(E, 2)
## [1] 1.35
sprintf('I would expected to end up with %s dollars', E*632)
## [1] "I would expected to end up with 855.058823529415 dollars"
round(pbinom(2, 10, .3), 3)
## [1] 0.383
sprintf("One would expect %s broken bulbs", 5*.3)
## [1] "One would expect 1.5 broken bulbs"
ppois(6, 5.5, lower=FALSE)
## [1] 0.313964
ppois(5, 5.7, lower=FALSE)
## [1] 0.5050151
ppois(1, 0.4*7)
## [1] 0.2310782
numer <- choose(19,8) * choose(6,0) + choose(19,7)*choose(6,1)
denom <- choose(25,8)
round(1- numer/denom, 3)
## [1] 0.651
numer <- sum(choose(15,0:6)*choose(10,6:0))
denom <- choose(25,8)
round(numer/denom, 3)
## [1] 0.164