I have three variables
Group-Set of Persons ex: {{David, Sebastian, Yousef}, {Boris, Mark}}
Person-Set ex: {David, Mark, Sebastian, Boris, Yousef}
Relation-Set ex: {{David, Mark}, {Sebastian, Boris}}
A Group-Set cannot have any person that are friends with each other.
A Group-Set cannot have duplicates.
I need to create a divide method thats called
divide(person-set, relation-set) and returns a group-set as the example above.
It needs to be solved recursively and loops are not allowed.
I already have a method called areFriends(Person, Person) that returns a boolean if they are friends or not.
This is what I got so far:
divide(ps, r){
divide(ps, r, gs){
let p1 = getRandom(ps);
p2 = getRandom(ps);
if(areFriends(p1, p2) = false){
gs.add(p1);
gs.add(p2);
}
remove(p1, ps);
if(getRandom(ps) != 0){
divide(ps, r, gs);
}
}
I've been dealing with this problem for a long time now and really need help with it. Thanks!