This is how I meant it:
http://pastebin.ubuntu.com/6573926

I've put in some comments to explain the strategy, and hope this explains it a little. I'm happy to discuss this solution with you, but I'm afraid it would take longer than the 24 hours you have left to wrestle with this task, and yet your bravery to take this on should be rewarded.