So back in college we had this homework (see the PDF, it's in Romanian because I'm Romanian, sorry). I didn't sovle it completely on my own back then, I was clueless until Niflo gave me some pointers (the algorithm in plain English, basically). I got ambitious a last week and redid it. I had forgotten the whole algorithm, so it was a fresh start :)
I managed to solve it on my own this time. Took me some time, though. The thought of talking with Niflo again came to me :P So I have now atoned.