r/PowerShell • u/mdowst • Dec 08 '25
Saving Christmas with PowerShell: Building a Reusable Matching Algorithm
This video isn’t just “here’s a script.” It walks step-by-step through the whole evolution of the solution:
- Start with a naive random shuffle
- Add constraints and filtering
- Introduce backtracking when things get messy
- Turn it all into a clean, reusable function
The end result is a robust matching engine you can adapt for scheduling, load balancing, on-call rotations, pairing systems, etc.
Watch: https://youtu.be/4uwQh6Nap5M
Code: https://www.dowst.dev/?p=3971
Feedback and ideas welcome!
13
Upvotes
View all comments
Show parent comment
2
u/mdowst Dec 10 '25
Interesting, I've never thought about doing the while loop with the array rather than the traditional FOR loop. I'm curious as to what makes it less error prone. I would think the standard for loop would give better control. Like you mentioned if you ever need to increment more than once. It can also be useful to breaking out of the loop early by setting the variable to a number higher than the max. (For those who are opposed to using breaks). The while could also cause confusion for other down the line because traditionally looked at something waiting for a condition, where a for seen for iterations.
I'm not opposed to using plural variable names, as long as it doesn't cause confusion. In this script I'll admit to using
$giver in $Giverswhich I normally try to avoid. I was using some old code for this video and must have overlooked that. Typically, I would do something like$GiversListto give a clear delineation from$giver.Thanks for the feedback. This is the type of stuff that helps everyone grow and learn new ways of doing things.