Question 1:

x <- 1.1
a <- 2.2
b <- 3.3

z <- x^(a^b)
print(z)
## [1] 3.61714
z <- (x^a)^b
print(z)
## [1] 1.997611
z <- 3*x^3 + 2*x^2 + 1
print(z)
## [1] 7.413

Question 2:

vec_1 <- c(seq(c(1:8)),7:1)
print(vec_1)
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
vec_2 <- 1:5
rep(x = vec_2, times = vec_2)
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
vec_3 <- 5:1
rep(x = vec_3, times = rev(vec_3))
##  [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1

Question 3:

set.seed(30)
cart <- runif(2)
polar <- sqrt((cart[1]^2)+cart[2]^2)
t <- atan(cart[2]/cart[1])
pcoords <- c(polar,t)
print(pcoords)
## [1] 0.4981248 1.3711636

Question 4:

  1. Queue + serpent gets in line
queue <- c("sheep", "fox", "owl", "ant")

queue[5] <- "serpent"

print(queue)
## [1] "sheep"   "fox"     "owl"     "ant"     "serpent"
  1. Sheep enters ark
queue <- queue[-1]
print(queue)
## [1] "fox"     "owl"     "ant"     "serpent"
  1. Donkey arrives and cuts to first
queue <- c("donkey", queue)
print(queue)
## [1] "donkey"  "fox"     "owl"     "ant"     "serpent"

d.Serpent leaves

queue <- queue[-5]
print(queue)
## [1] "donkey" "fox"    "owl"    "ant"

e.Owl leaves

queue <- queue[-3]
print(queue)
## [1] "donkey" "fox"    "ant"

f.Aphid arrives and goes in front of ant

queue <- c(queue[1:2], "aphid", queue[3])
print(queue)
## [1] "donkey" "fox"    "aphid"  "ant"
  1. Find the aphid
print(which(queue == "aphid"))
## [1] 3

Question 5:

v <- seq(1:100)
v <- v[v %% 2 != 0 & v %% 3 !=0 & v %% 7 != 0]
print(v)
##  [1]  1  5 11 13 17 19 23 25 29 31 37 41 43 47 53 55 59 61 65 67 71 73 79 83 85
## [26] 89 95 97