C
C#2y ago
malkav

❔ ✅ Semi-Random-Generator

So I'm trying to generate a list for scheduling people to a task. What I intend is to generate the list in such a way that each person is combined with one other person and gets either one of three tasks, I want the people to be combined with another in such a way that for a complete iteration of the people, everyone gets paired with another person once and they get each of the three tasks in a repeating order. Group 1: PersonA + PersonB => Task_1 || Person C + PersonD => Task_2 || PersonE => Task_3 Next iteration it should be a version of this where no person is paired with the same person twice, untill all persons have had all three tasks once. Then repeat the gesture yes there are only 5 people to choose from and three tasks. That is a fixed amount Help?
14 Replies
lycian
lycian2y ago
what have you tried so far?
malkav
malkavOP2y ago
Basically create an array of people, and an array of tasks, and do a random number between 0 and 4 (or 0 and 2 for the tasks) and create a dictionary with those items. But that doesn't follow the rules. And from here I'm not really sure where to start
lycian
lycian2y ago
I'd start with figuring out how to find pairs of people, that seems to be where you're having issues. Maybe think of just ordering the queue of people such that indexes help map to tasks:
var people = new Person[] { ... }; // figure out ordering here
people[0] + people[1] => task1;
people[2] + people[3] => task2;
people[4] => task3;
var people = new Person[] { ... }; // figure out ordering here
people[0] + people[1] => task1;
people[2] + people[3] => task2;
people[4] => task3;
does that make sense?
malkav
malkavOP2y ago
I'm not sure I follow entirely... Yes I was stuck mostly on paring people, regardless of tasks. And I wanted to figure some algorithm where people[x] + people[y] would always be.. hrm.. people[x] + people[y] is the same as people[y] + people[x] each person would be paired with each other person once and only once from there it would pair these groups with tasks but since there are only 5 people, it would make a group of 2 + 2 + 1 so task_1 = 2 people, task_2 = 2 people, and task_3 = free, so 1 person
lycian
lycian2y ago
correct, people[x] + people[y] would always be the same as the inverse
malkav
malkavOP2y ago
but the crux is that I always have to have a person alone in a group too 😅 So hard-coded it should look something like this but then I'd need it randomized sorta I guess?:
string[] group = {
people[0] + people[1],
people[0] + people[2],
people[0] + people[3],
people[0] + people[4],
people[1] + people[2],
people[1] + people[3],
people[1] + people[4],
people[2] + people[3],
people[2] + people[4],
people[3] + people[4],
people[0],
people[1],
people[2],
people[3],
people[4]
};
string[] group = {
people[0] + people[1],
people[0] + people[2],
people[0] + people[3],
people[0] + people[4],
people[1] + people[2],
people[1] + people[3],
people[1] + people[4],
people[2] + people[3],
people[2] + people[4],
people[3] + people[4],
people[0],
people[1],
people[2],
people[3],
people[4]
};
and then randomized I'd need to appoint the tasks too 😅
lycian
lycian2y ago
do you need it randomized, or do you need to find all combinations possible?
malkav
malkavOP2y ago
Sorry wasn't done yet The idea behind this is that I have a list of "dates" And for each of these dates I have three tasks, let's call em groceries, dishwashing, and lazy (lazy just means the one single person is free of tasks at that date) now I want each date to have a random group do one task, another random group does task 2, and a single person is free of tasks A group can never do the same task twice in a row, and this group cannot do the other task the same time as they do the first task. So it would be group_1 does task_1, group_2 does task_2, and single_person_group does nothing this same configuration cannot happen twice in a single repeat so I cannot have
date 1: group_1 does task_1, group_2 does task_2, and single_person_group does nothing date 2: group_3 does task_1, group_4 does task_2, and single_person_group does nothing date 3: group_5 does task_1, group_6 does task_2, and single_person_group does nothing date 4: group_7 does task_1, group_8 does task_2, and single_person_group does nothing .....
the eventual result will repeat forever until there are no more dates So I think find all combinations possible? I mean in an excel I can probably just manually do it, but it would be so much better in this way, because in an excel doing it manually would make me biassed?
lycian
lycian2y ago
gotcha, in that case I'd start with randomizing the list of people then given that randomized set find all pairs (can be hardcoded or done at runtime)
malkav
malkavOP2y ago
also I just noticed, my example is flawed, I missed the "wrong" example in there 😅
lycian
lycian2y ago
var randomizedPeople = AllPeople.OrderBy(p => rand.Next()).ToArray();
var group1 = (randomizedPeople[0], randomizedPeople[1]);
// ...
var randomizedPeople = AllPeople.OrderBy(p => rand.Next()).ToArray();
var group1 = (randomizedPeople[0], randomizedPeople[1]);
// ...
if you want to do the pairs programmatically it's still the same thing, you just remove the hardcoding and calculate them.
malkav
malkavOP2y ago
I'm not sure I follow you here.. I mean, I think very literal I have this:
string[] groups = {
$"{people[0]} + {people[1]}",
$"{people[0]} + {people[2]}",
$"{people[0]} + {people[3]}",
$"{people[0]} + {people[4]}",
$"{people[1]} + {people[2]}",
$"{people[1]} + {people[3]}",
$"{people[1]} + {people[4]}",
$"{people[2]} + {people[3]}",
$"{people[2]} + {people[4]}",
$"{people[3]} + {people[4]}",
$"{people[0]}",
$"{people[1]}",
$"{people[2]}",
$"{people[3]}",
$"{people[4]}"
};

Dictionary<string, Sched> pairedGroceries = new();
Dictionary<string, Sched> pairedDishwashing = new();
Dictionary<string, Sched> pairedFree = new();
foreach (var group in groups)
{
if (!group.Contains('+'))
{
pairedFree.Add(group, Sched.Free);
continue;
}
pairedGroceries.Add(group, Sched.Groceries);
pairedDishwashing.Add(group, Sched.Dishwasher);
}
string[] groups = {
$"{people[0]} + {people[1]}",
$"{people[0]} + {people[2]}",
$"{people[0]} + {people[3]}",
$"{people[0]} + {people[4]}",
$"{people[1]} + {people[2]}",
$"{people[1]} + {people[3]}",
$"{people[1]} + {people[4]}",
$"{people[2]} + {people[3]}",
$"{people[2]} + {people[4]}",
$"{people[3]} + {people[4]}",
$"{people[0]}",
$"{people[1]}",
$"{people[2]}",
$"{people[3]}",
$"{people[4]}"
};

Dictionary<string, Sched> pairedGroceries = new();
Dictionary<string, Sched> pairedDishwashing = new();
Dictionary<string, Sched> pairedFree = new();
foreach (var group in groups)
{
if (!group.Contains('+'))
{
pairedFree.Add(group, Sched.Free);
continue;
}
pairedGroceries.Add(group, Sched.Groceries);
pairedDishwashing.Add(group, Sched.Dishwasher);
}
but this only makes three groups for each of the combinations I guess? but then I need to make sure I remove any duplicates for a single "repetition" I guess also, Sched is simply an enum
internal enum Sched
{
// With [Description()] tags
Groceries = 1,
Dishwasher = 2,
Free = 3
}
internal enum Sched
{
// With [Description()] tags
Groceries = 1,
Dishwasher = 2,
Free = 3
}
but I'd like to do this programatically if I'm even on the right track 😅
lycian
lycian2y ago
Sorry, I went out for the rest of the day (it was weekend for me). You're somewhat on the right track. To get programmatic for an enum you can do
var schedValues = Enum.GetValues<Sched>();
var schedValues = Enum.GetValues<Sched>();
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server