For the lazy, solutions are at http://pastebin.com/XJZTFGHP
A few different solutions: http://pastebin.com/Mf6ZmhfA