Who engineered this C++ recursive algorithm? It's giving me a migraine. If I can't debug this in five minutes I'm throwing my monitor off the balcony.