# Mindanao State University
# General Santos City
# Loop Structures in R
#How to create Dynamic Numeric passwords in R.
# Submitted by: Dongosa, Davy D. 1-BS MATH
# Math 108
# Given a random set of integers, generate a 1 block triple for loop for the sequence of consecutive integers that gives the maximum possible sum
UniversalSet <- 100:100
Size <- 12
RandomSet <- sample(UniversalSet, Size, rep= FALSE)
dat <- list()
Sums <- list()
counter <- 0
for (i in 1:(Size-3)) {
for (j in 3:5) {
data <- RandomSet[i]
for (k in 1:j) {
data <- c(data, RandomSet[i + k])
}
counter <- counter + 1
dat[[counter]] <- data
Sums[[counter]] <- sum(data)
}
}
head(dat)
## [[1]]
## [1] 20 73 49 57
##
## [[2]]
## [1] 20 73 49 57 31
##
## [[3]]
## [1] 20 73 49 57 31 25
##
## [[4]]
## [1] 73 49 57 31
##
## [[5]]
## [1] 73 49 57 31 25
##
## [[6]]
## [1] 73 49 57 31 25 55
tail(dat)
## [[1]]
## [1] 74 10 87 86
##
## [[2]]
## [1] 74 10 87 86 37
##
## [[3]]
## [1] 74 10 87 86 37 NA
##
## [[4]]
## [1] 10 87 86 37
##
## [[5]]
## [1] 10 87 86 37 NA
##
## [[6]]
## [1] 10 87 86 37 NA NA
RandomSet
## [1] 20 73 49 57 31 25 55 74 10 87 86 37