# Mindanao State University 
# General Santos City 
# Loop Structures in R
#How to create Dynamic Numeric passwords in R. 
# Submitted by: Angga, Princess Joy, 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] 60 24 81 83
## 
## [[2]]
## [1] 60 24 81 83 61
## 
## [[3]]
## [1] 60 24 81 83 61  1
## 
## [[4]]
## [1] 24 81 83 61
## 
## [[5]]
## [1] 24 81 83 61  1
## 
## [[6]]
## [1] 24 81 83 61  1 44
tail(dat)
## [[1]]
## [1] 41 17 56 28
## 
## [[2]]
## [1] 41 17 56 28 72
## 
## [[3]]
## [1] 41 17 56 28 72 NA
## 
## [[4]]
## [1] 17 56 28 72
## 
## [[5]]
## [1] 17 56 28 72 NA
## 
## [[6]]
## [1] 17 56 28 72 NA NA
RandomSet
##  [1] 60 24 81 83 61  1 44 41 17 56 28 72