Assuming there is a list of teachers and students as defined in the below sequence.
- Teacher
- Student
- Student
- Student
- Teacher
- Student
- Teacher
A teacher can teach himself/herself and other student before the next teacher. Everyone in the list/sequence need to be taught. A teacher cannot teach another teacher.
Expected output is as below. The first element in the output should be read as #1 teaches 1,2,3,4 and #5 teaches 5,6 and #7 teaches 7.
[
{ 1:1,2,3,4; 5:5,6 ; 7:7 },
{ 1:1,2,3,4; 5:5 ; 7:6,7 },
{ 1:1,2 ; 5:3,4,5,6 ; 7:7 },
{ 1:1,2 ; 5:3,4,5 ; 7:6,7 },
{ 1:2,3 ; 5:4,5,6 ; 7:7 },
{ 1:2,3 ; 5:4,5 ; 7:6,7 },
{ 1:1 ; 5:2,3,4,5,6; 7:7 },
{ 1:1 ; 5:2,3,4,5 ; 7:6,7 }
]
Tried cartesian product like
var items = teachers.SelectMany(x => students.Where(p => p.Sequence < x.Sequence ), (x, y) => new { TeacherSequence = x.Sequence , StudentSequence = y.Sequence })
but this doesn’t work. Any ideas ?