I am facing a unique situation where I have 31 students in my class and I want them to be divided into 8 groups (4 each with exception of one with only 3 members). The specific rule I am trying to follow is that no student should work with another student if they have already worked together.
I need to create three group sets (that includes 8 groups each time) for three weeks and follow this logic. Manually it is a tad complicated and I was hoping I can write a code in R to get the desired result, however I am at loss, as to how to correct the following as it is not giving me the write sequence in some cases.
# List of student names
students <- c("Student1", "Student2", "Student3", "Student4", "Student5", "Student6", "Student7", "Student8", "Student9", "Student10",
"Student11", "Student12", "Student13", "Student14", "Student15", "Student16", "Student17", "Student18", "Student19", "Student20",
"Student21", "Student22", "Student23", "Student24", "Student25", "Student26", "Student27", "Student28", "Student29", "Student30", "Student31")
# Number of students
num_students <- length(students)
# Number of rounds
num_rounds <- 3
# Group size
group_size <- 4
# Create an empty list to store groups
all_groups <- list()
# Function to create groups
create_groups <- function(students, group_size) {
shuffled_students <- sample(students)
groups <- split(shuffled_students, ceiling(seq_along(shuffled_students)/group_size))
return(groups)
}
# Loop through each round
for (round in 1:num_rounds) {
# Create groups for the current round
groups <- create_groups(students, group_size)
# Append the groups to the list
all_groups[[paste0("Round", round)]] <- groups
}
# Print the results
for (round in 1:num_rounds) {
cat("Round", round, ":\n")
print(all_groups[[paste0("Round", round)]])
cat("\n")
}
And once the right sequence is found, is there a way to find out if that worked or not?