#Alwyn E Felisilda
#MAT108
#May !5, 2023
#Submitted to: Carlito Daarol

# Define the randomset variable
randomset <- c(8, 10, 12, 13, 9, 11, 16, 18, 6)

# Case of 4 consecutive elements
consecutive_length <- 4
for (i in 1:(length(randomset) - consecutive_length + 1)) {
  subset <- randomset[i:(i + consecutive_length - 1)]
  
  # Process the subset or perform any desired operations
  print(subset)
}
## [1]  8 10 12 13
## [1] 10 12 13  9
## [1] 12 13  9 11
## [1] 13  9 11 16
## [1]  9 11 16 18
## [1] 11 16 18  6
# Case of 5 consecutive elements
consecutive_length <- 5
for (i in 1:(length(randomset) - consecutive_length + 1)) {
  subset <- randomset[i:(i + consecutive_length - 1)]
  
  # Process the subset or perform any desired operations
  print(subset)
}
## [1]  8 10 12 13  9
## [1] 10 12 13  9 11
## [1] 12 13  9 11 16
## [1] 13  9 11 16 18
## [1]  9 11 16 18  6
# Case of 6 consecutive elements
consecutive_length <- 6
for (i in 1:(length(randomset) - consecutive_length + 1)) {
  subset <- randomset[i:(i + consecutive_length - 1)]
  
  # Process the subset or perform any desired operations
  print(subset)
  
  
  
  
  
}
## [1]  8 10 12 13  9 11
## [1] 10 12 13  9 11 16
## [1] 12 13  9 11 16 18
## [1] 13  9 11 16 18  6
# Case of 4 consecutive elements
for (i in 1:(length(randomset) - 3)) {
  subset <- randomset[i:(i+3)]
  if (all(subset == randomset[i:(i+3)])) {
    print(paste("4 consecutive elements found:", subset))
  } else {
    print("No 4 consecutive elements found.")
  }
}
## [1] "4 consecutive elements found: 8"  "4 consecutive elements found: 10"
## [3] "4 consecutive elements found: 12" "4 consecutive elements found: 13"
## [1] "4 consecutive elements found: 10" "4 consecutive elements found: 12"
## [3] "4 consecutive elements found: 13" "4 consecutive elements found: 9" 
## [1] "4 consecutive elements found: 12" "4 consecutive elements found: 13"
## [3] "4 consecutive elements found: 9"  "4 consecutive elements found: 11"
## [1] "4 consecutive elements found: 13" "4 consecutive elements found: 9" 
## [3] "4 consecutive elements found: 11" "4 consecutive elements found: 16"
## [1] "4 consecutive elements found: 9"  "4 consecutive elements found: 11"
## [3] "4 consecutive elements found: 16" "4 consecutive elements found: 18"
## [1] "4 consecutive elements found: 11" "4 consecutive elements found: 16"
## [3] "4 consecutive elements found: 18" "4 consecutive elements found: 6"
# Case of 5 consecutive elements
for (i in 1:(length(randomset) - 4)) {
  subset <- randomset[i:(i+4)]
  if (all(subset == randomset[i:(i+4)])) {
    print(paste("5 consecutive elements found:", subset))
  } else {
    print("No 5 consecutive elements found.")
  }
}
## [1] "5 consecutive elements found: 8"  "5 consecutive elements found: 10"
## [3] "5 consecutive elements found: 12" "5 consecutive elements found: 13"
## [5] "5 consecutive elements found: 9" 
## [1] "5 consecutive elements found: 10" "5 consecutive elements found: 12"
## [3] "5 consecutive elements found: 13" "5 consecutive elements found: 9" 
## [5] "5 consecutive elements found: 11"
## [1] "5 consecutive elements found: 12" "5 consecutive elements found: 13"
## [3] "5 consecutive elements found: 9"  "5 consecutive elements found: 11"
## [5] "5 consecutive elements found: 16"
## [1] "5 consecutive elements found: 13" "5 consecutive elements found: 9" 
## [3] "5 consecutive elements found: 11" "5 consecutive elements found: 16"
## [5] "5 consecutive elements found: 18"
## [1] "5 consecutive elements found: 9"  "5 consecutive elements found: 11"
## [3] "5 consecutive elements found: 16" "5 consecutive elements found: 18"
## [5] "5 consecutive elements found: 6"
# Case of 6 consecutive elements
for (i in 1:(length(randomset) - 5)) {
  subset <- randomset[i:(i+5)]
  if (all(subset == randomset[i:(i+5)])) {
    print(paste("6 consecutive elements found:", subset))
  } else {
    print("No 6 consecutive elements found.")
  }
}
## [1] "6 consecutive elements found: 8"  "6 consecutive elements found: 10"
## [3] "6 consecutive elements found: 12" "6 consecutive elements found: 13"
## [5] "6 consecutive elements found: 9"  "6 consecutive elements found: 11"
## [1] "6 consecutive elements found: 10" "6 consecutive elements found: 12"
## [3] "6 consecutive elements found: 13" "6 consecutive elements found: 9" 
## [5] "6 consecutive elements found: 11" "6 consecutive elements found: 16"
## [1] "6 consecutive elements found: 12" "6 consecutive elements found: 13"
## [3] "6 consecutive elements found: 9"  "6 consecutive elements found: 11"
## [5] "6 consecutive elements found: 16" "6 consecutive elements found: 18"
## [1] "6 consecutive elements found: 13" "6 consecutive elements found: 9" 
## [3] "6 consecutive elements found: 11" "6 consecutive elements found: 16"
## [5] "6 consecutive elements found: 18" "6 consecutive elements found: 6"