Okay, really complex title aside, I’ll try to explain the problem I had and the interesting way I found to solve it. This may not be the best or the most optimized way, but I really liked this solution and would like to share it.
Also, although I do prefer Python, this post is in C#, since that was the language I encountered this problem in.
So here is the problem.