Question 1

Nicola throws two dice at the same time. Then, she adds together the numbers on the top faces of the two dice. What is the probability the sum is less than or equal to 7?

die1 <- 1:6
die2 <- 1:6
N <- 1e5
counter <- 0
for (i in 1:N) {
  roll1 <- sample(x = die1,size = 1,replace = T)
  roll2 <- sample(x = die2,size = 1,replace = T)
  if (roll1 + roll2 <= 7) {
    counter <- counter + 1
  }
}
probability <- counter / N
cat("The probability that the sum is less than or equal to 7 is:",probability,"\n")
## The probability that the sum is less than or equal to 7 is: 0.58323

Question 2

Put \([4958,8945,8495,5849,5984,5948]\) in ascending 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(4958,8945,8495,5849,5984,5948))
q2_data %>%
  arrange(Number) # arrange(): ascending order
##   Number
## 1   4958
## 2   5849
## 3   5948
## 4   5984
## 5   8495
## 6   8945

Question 3

Construct the corresponding polygon given by the \((x,y)\) data below.

# install.packages("tidyverse")
library(tidyverse)
q3_data <- data.frame(X = c(1,-1,-1,-4,-4,4,4,1),
                      Y = c(1,1,8,8,10,10,8,8))
ggplot(q3_data,aes(x = X,y = Y)) +
  geom_polygon(fill = "green",col = "black",lwd = 1.25) +
  geom_point(size = 3) +
  coord_equal() +
  theme_gray()

Question 4

What is \(\sqrt[3] {-467}\) correct to 2 decimal places?

# install.packages("pracma")
library(pracma)
## 
## Attaching package: 'pracma'
## The following object is masked from 'package:purrr':
## 
##     cross
value <- nthroot(x = -467,n = 3) # x = -467 (our value), n = 3 (cube root)
cat("Value:",round(value,2),"\n")
## Value: -7.76

Question 5

What is \(\int (x + 2) e^x \space 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((x + 2) * exp(x) ~ x)
anti_f <- antiD(f(x) ~ x)
anti_f
## function (x, C = 0) 
## {
##     F <- makeF((x + 2) * exp(x))
##     evalFun(F, x = x, .const = C)
## }
## <environment: 0x000001fb4642ef20>