Initial commit.
Reworking the solution, much cleaner now. There are a bunch of floating point hacks though.