Question 1

There are ten marbles in a bag: 4 yellow, 3 gray, 2 red, and 1 blue. You mix them up and choose one marble from the bag without looking and note its color. You do not put the marble back, mix the rest of the marbles up, and then choose a second marble without looking. What is the probability both marbles are gray?

marbles_bag <- c("Yellow","Yellow","Yellow","Yellow","Gray","Gray","Gray","Red","Red","Blue")
counter <- 0
N <- 10000
for (x in 1:N) {
  pick <- sample(x = marbles_bag,size = 2,replace = FALSE)
  if (all(pick == "Gray")) {
    counter <- counter + 1
  }
}
probability <- counter / N
cat("The probability of both marbles being gray is:",probability,"\n")
## The probability of both marbles being gray is: 0.0646

Question 2

How many prime numbers are there between 30 and 39 inclusive?

  1. Method 1
# install.packages(c("comprehenr","pracma"))
library(comprehenr)
## Warning: package 'comprehenr' was built under R version 4.5.2
library(pracma)
prime_numbers <- to_vec(for (x in 30:39) if (isprime(x) == TRUE) x)
cat("There are",length(prime_numbers),"prime numbers between 30 and 39 inclusive.","\n")
## There are 2 prime numbers between 30 and 39 inclusive.
  1. Method 2
# install.packages("pracma")
library(pracma)
prime_counter <- 0
for (y in 30:39) {
  if (isprime(y) == TRUE) {
    prime_counter <- prime_counter + 1
  }
}
cat("There are",prime_counter,"prime numbers between 30 and 39 inclusive.","\n")
## There are 2 prime numbers between 30 and 39 inclusive.