Help with matching algo
Unanswered
West African Lion posted this in #help-forum
West African LionOP
Apologies for what is most likely a question I'm missing a simple answer for, but my brain isn't functioning so any help would be greatly appreciated!
Given the following
This is for in-person speed dating (so out of the men/women in this hetero event for example, this is the one that has less people).
I'm trying to generate matches, and keep records so the same match doesn't happen twice. In addition to that, I'm trying to make sure that if someone was skipped last round, they are prioritize this one. The following is the code to try and solve this issue, but I'm getting odd behaviors... I'm testing with 3 users at the moment. My expectation is that each time, a single user will be returned in the skippedAttendees list but sometimes I get nothing, and I'm very confused.
My current code:
I'm attaching an image of what the state of the lists are after running 3 rounds. I'm using a JSON to keep track of the matches in the following way:
Any help would be greatly appreciated! A video is also attached if you'd like to see what this is representing
Given the following
skippedAttendees
= List of attendees that didn't have a match last roundsmallerSet
= Out of the total attendees, this is the smaller list of attendeesThis is for in-person speed dating (so out of the men/women in this hetero event for example, this is the one that has less people).
weightedAttendeeList
= A combination of both the smallerSet & skippedAttendees
I'm trying to generate matches, and keep records so the same match doesn't happen twice. In addition to that, I'm trying to make sure that if someone was skipped last round, they are prioritize this one. The following is the code to try and solve this issue, but I'm getting odd behaviors... I'm testing with 3 users at the moment. My expectation is that each time, a single user will be returned in the skippedAttendees list but sometimes I get nothing, and I'm very confused.
My current code:
const weightedAttendeeList = [...skippedAttendees, ...smallerSet];
for (const attendeeId of weightedAttendeeList) {
const matchId = getMatch(attendeeId, previousMatches, largerSet);
if (!matchId) {
continue;
}
const table_id = Math.floor(seats / table_size);
if (table_id > table_count) {
break;
}
const table = `Table ${String.fromCharCode(table_id + 65)}`;
seats += 2;
matchInfoArray.push({
event_round_id: round_id,
attendee_id: attendeeId,
location: table,
match_info: readyAttendeesList.find(({ id }) => id === matchId) as Json,
});
matchInfoArray.push({
event_round_id: round_id,
attendee_id: matchId,
location: table,
match_info: readyAttendeesList.find(
({ id }) => id === attendeeId
) as Json,
});
if (newMatchList[attendeeId]) {
newMatchList[attendeeId].push(matchId);
} else {
newMatchList[attendeeId] = [matchId];
}
if (newMatchList[matchId]) {
newMatchList[matchId].push(attendeeId);
} else {
newMatchList[matchId] = [attendeeId];
}
}
readyAttendeesList.map((attendee) => {
if (!matchInfoArray.some((match) => match.attendee_id == attendee.id)) {
noMatchList.push(attendee.id);
}
});
return { matchInfoArray, newMatchList, noMatchList };
};
I'm attaching an image of what the state of the lists are after running 3 rounds. I'm using a JSON to keep track of the matches in the following way:
{
<uuid>: [List of previously matched uuids]
}
// For example
{
"3": ["1","2"],
"2": ["3"],
"1": ["3]
}
Any help would be greatly appreciated! A video is also attached if you'd like to see what this is representing
4 Replies
I can’t help you solve this but I can just give some quick tips
1) write a unit test that tests your algorithm produces the right results
2) use claude or OpenAI, tell it what the problem is and what you’re trying to solve
3) rerun your unit test until it passes
2) use claude or OpenAI, tell it what the problem is and what you’re trying to solve
3) rerun your unit test until it passes
Rinse and repeat
West African LionOP
Thank you, that is super helpful!