Question 1

Your friend asks you to choose one card from the seven cards in his hand without looking. Which suit is the least likely to be chosen? Use a Monte Carlo simulation here.

set.seed(123) # for reproducibility
seven_cards <- c("8 Spades","4 Hearts","2 Clubs","2 Hearts","4 Diamonds","6 Clubs","2 Spades")
card_suits <- sub(".* ","",seven_cards)
draws <- sample(x = card_suits,size = 1e6,replace = T) # 1e6 - 1,000,000 trials
prop_table <- prop.table(table(draws))
prop_table
## draws
##    Clubs Diamonds   Hearts   Spades 
## 0.285324 0.143154 0.285694 0.285828

Question 2

Place the four numbers \([2413,2341,4123,4312]\) in descending order.

# install.packages("tidyverse")
library(tidyverse)
## Warning: package 'lubridate' was built under R version 4.5.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.1     ✔ stringr   1.5.2
## ✔ ggplot2   4.0.0     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
q2_data <- data.frame(Number = c(2413,2341,4123,4312))
q2_data %>%
  arrange(desc(Number)) # arrange(): ascending order, desc(): descending order
##   Number
## 1   4312
## 2   4123
## 3   2413
## 4   2341

Question 3

What is the cube root of -2197?

# install.packages("pracma")
library(pracma)
## 
## Attaching package: 'pracma'
## The following object is masked from 'package:purrr':
## 
##     cross
value <- nthroot(x = -2197,n = 3)
cat("The cube root of -2197 is:",value,"\n")
## The cube root of -2197 is: -13

Question 4

We throw two dice labeled 1 to 6. Use a Monte Carlo simulation to find the probability that the product is an odd number.

die1 <- 1:6
die2 <- 1:6
counter <- 0
N <- 1e6
for (i in 1:N) {
  roll1 <- sample(x = die1,size = 1,replace = T)
  roll2 <- sample(x = die2,size = 1,replace = T)
  if ((roll1 * roll2) %% 2 == 1) {
    counter <- counter + 1
  }
}
probability <- counter / N
cat("The probability that the product is an odd number is:",probability,"\n")
## The probability that the product is an odd number is: 0.250297

Question 5

Evaluate the following indefinite integral below.

\[\int \sin(x) dx\]

# install.packages(c("ggformula","mosaicCalc"))
library(ggformula)
## Warning: package 'ggformula' was built under R version 4.5.2
## Loading required package: scales
## 
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor
## Loading required package: ggiraph
## Warning: package 'ggiraph' was built under R version 4.5.2
## Loading required package: ggridges
## Warning: package 'ggridges' was built under R version 4.5.2
## 
## New to ggformula?  Try the tutorials: 
##  learnr::run_tutorial("introduction", package = "ggformula")
##  learnr::run_tutorial("refining", package = "ggformula")
library(mosaicCalc)
## Warning: package 'mosaicCalc' was built under R version 4.5.2
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
## 
##     D
f <- makeFun(sin(x) ~ x)
anti_f <- antiD(f(x) ~ x)
anti_f
## function (x, C = 0) 
## C - cos(x)