solved 12/Haskell (horribly inefficient)