I really want to port
this answer to a better golfing language than Pyth. Vyxal seemed the most promising option, but that's not saying much. It's really sad that it has no eval in the online version, like Pyth does. Eval is the only way a program like this can be implemented. But still, I'd at least be able to demonstrate the program on replit.com.