#for n = 0
#h(x,0) = 1
#for n=1
#h(x, 1)= 1 + x
#for n = 2
#h(x, 2)= 1 + x + x^2
n=6
h=1
x=1
for (i in 1:n){
h <- h + x^i
#print(h)
}
print(h)
## [1] 7
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#sample <- c(1,2,3,4,5,6,7)
sum_3rd <- function(x) {
x[seq(0, length(x), by = 3)] %>%
sum()
}
#sum_3rd(sample)
#test <- c(10:1, 50)
Minimum_function <- function(x){
x.min <- x[1]
for (i in 1:length(x)){
if (x[i] < x.min) {
x.min <- x[i]
}
}
print(x.min)
}
#Minimum_function(test)
#set.seed(1) for testing
craps_testing <- function() {
roll_1 <- sum(ceiling(6*runif(2)))
if (roll_1 == 7 | roll_1 == 11) {print( paste("rolled a", roll_1, "you win"))}
else {
print(roll_1)
dice_roll <- sum(ceiling(6*runif(2)))
while (dice_roll != roll_1 & dice_roll != 7 & dice_roll != 11)
{
print(dice_roll)
dice_roll <- sum(ceiling(6*runif(2)))
}
if (dice_roll == roll_1) print(paste("Your roll matched your first roll, YOU WIN!!!", dice_roll))
else print(paste("You lose, life is hard...", dice_roll))
}}
craps_testing()
## [1] 5
## [1] "You lose, life is hard... 11"
Answer
craps <- function() {
roll_1 <- sum(ceiling(6*runif(2)))
if (roll_1 == 7 | roll_1 == 11) {print( paste("rolled a", roll_1, "you win"))}
else {
dice_roll <- sum(ceiling(6*runif(2)))
while (dice_roll != roll_1 & dice_roll != 7 & dice_roll != 11)
{
dice_roll <- sum(ceiling(6*runif(2)))
}
if (dice_roll == roll_1) print("Your roll matched your first roll, YOU WIN!!!")
else print("You lose, life is hard...")
}}
craps()
## [1] "rolled a 11 you win"
t <- seq(0, 10, by = 0.0001)
x <- sqrt(t) *cos(2*pi*t)
y <- sqrt(t) *sin(2*pi*t)
plot(x, y, cex=.1)