Question 1

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

Question 1a

z <- x^{a^b}
print(z)
## [1] 3.61714

Question 1b

z <- {x^a}^b

print(z)
## [1] 1.997611

Question 1c

z <- 3*{x^3} + 2*{x^2} + 1

print(z)
## [1] 7.413

Question 2

Question 2a

vec_a <- c(seq(1:8), seq(7,1))

print(vec_a)
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1

Question 2b

vec_b <- c(seq(1:5))

vec_b <- rep(x = vec_b, times = vec_b)

print(vec_b)
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5

Question 2c

vec_c1 <- c(seq(1:5))

vec_c2 <- c(seq(5,1))

vec_c <- rep(x = vec_c2, times = vec_c1)

print(vec_c)
##  [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1

Question 3

coord <- runif(2)

print(coord)
## [1] 0.9966781 0.4018925
polar_coord <- c(sqrt(coord[1]^2+coord[2]^2),atan(coord[2]/coord[1]))

print(polar_coord)
## [1] 1.0746557 0.3832895

Question 4

queue <- c("sheep", "fox", "owl", "ant")

Question 4a

# The serpent arrives and gets in line
queue[5] <- "serpent"
print(queue)
## [1] "sheep"   "fox"     "owl"     "ant"     "serpent"

Question 4b

# The sheep enters the Ark 
queue <- queue[-1]
print(queue)
## [1] "fox"     "owl"     "ant"     "serpent"

Question 4c

# The donkey arrives and talks his way to the front of the line
queue <- c("donkey", queue)
print(queue)
## [1] "donkey"  "fox"     "owl"     "ant"     "serpent"

Question 4d

# The serpent gets impatient and leaves 
queue <- queue[-5]
print(queue)
## [1] "donkey" "fox"    "owl"    "ant"

Question 4e

# The owl gets bored and leaves 
queue <- queue[-3]
print(queue)
## [1] "donkey" "fox"    "ant"

Question 4f

# The aphid arrives and the ant invites him to cut in line.
queue <- c(queue[1:2], "aphid", queue[3])
print(queue)
## [1] "donkey" "fox"    "aphid"  "ant"

Question 4g

# Finally, determine the position of the aphid in the line.
which(queue == "aphid")
## [1] 3

Question 5

vec <- 1:100
vec <- which((vec%%2 != 0) & (vec%%3 != 0) & (vec%%7 != 0))
print(vec)
##  [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