Anonymous Monk,
As tilly would say, I am a displaced mathematician. I realize the inefficiency of the algorithm and I appreciate you pointing it out. In fact, the code itself could have been made a lot more concise by sacrificing readability. I was just trying to help the new monk out. I figured it was easy enough to understand and modify for their purposes.