I've written stuff similar to this using Genetic Algorithms so I could get a "fairly good" answer within a few minutes instead of hours of heavy CPU. Abusive comment hidden. (Show it anyway.)