Question 1

## 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

The bar graph shows the number of kilograms of oranges bought by five friends. How many kilograms of oranges did Ramiro, Tom, and Ursula buy altogether?

# install.packages("tidyverse")
library(tidyverse)
q1_data <- data.frame(Name = c("Ramiro","Sian","Tom","Ursula","Vikram"),
                 kg = c(2,6,8,6,12))
answer <- q1_data %>%
  filter(Name %in% c("Ramiro","Tom","Ursula")) %>%
  select(kg) %>%
  sum()
cat("Ramiro, Tom, and Ursula bought",answer,"kilograms of oranges altogether.","\n")
## Ramiro, Tom, and Ursula bought 16 kilograms of oranges altogether.

Question 2

What is the least common multiple of 18 and 24?

# install.packages("pracma")
library(pracma)
## 
## Attaching package: 'pracma'
## The following object is masked from 'package:purrr':
## 
##     cross
Lcm(a = 18,b = 24)
## [1] 72

Question 3

The diagram shows a spinner made of a piece of card in the shape of a regular heptagon, with a toothpick pushed through its center. The seven triangles are numbered from 1 to 7. Each time, the spinner is spun until it lands on one of the seven edges of the heptagon. The spinner is spun six times. Use a Monte Carlo simulation to calculate the probability of three or more fives.

spinner <- 1:7
counter <- 0
N <- 1e5
for (i in 1:N) {
  spins <- sample(x = spinner,size = 6,replace = T)
  if (sum(spins == 5) >= 3) {
    counter <- counter + 1
  }
}
probability <- counter / N
cat("The probability is:",probability,"\n")
## The probability is: 0.04301