We needed to form new groups in my class of 28 students (seven groups of four), so I had the idea to allow some student choice. Students were able to choose six others that they would prefer to be with, and three others that they would prefer not be in a group with.
Each student is assigned a number from 1 to 28, and I generated possible combinations of 4 students chosen from those 28 (20 475 possible combinations).
Then I eliminated combinations that that contained a given student and a student that they indicated a preference for not being with, which narrowed it down to 7714 possible combinations.
From these 7714 combinations, I built sets of 28 unique students (seven groups of four with no repeating numbers in a set). This resulted in 259 possible class group configurations.
I then assigned points to those sets based on student preferences, one point for every "I want to be with ___" that was fulfilled. The set with the highest points was then chosen, and the numbers translated back into names.
That's just a broad overview of the algorithm design. Just for fun, I did different parts in Wolfram Cloud, Python, Javascript, and Excel.