You don't want to do full search here. You want to do a "branch and bound" search, keeping track of the current best value (which suggests the State monad) and then terminating searches of subtrees when the best possible value for that subtree is worse than the current global best possible.

I haven't looked into doing this in Haskell, but it should be a lot faster than trying to search the full tree.


On Mon, Apr 27, 2015 at 9:23 AM, Animesh Saxena <animeshsaxena@icloud.com> wrote:
let cities = 6
let clinics = 10
let populations = [1,10000,2,3,400,1]
let nparts n k = filter ((==n) . sum)  $ replicateM k [1..n]
let d2 = nparts clinics cities
let d1 = map maximum (map (\x -> zipWith (/) populations (map (\n-> fromIntegral n) x)) $ d2)
maximum $ zipWith (\n x -> (n `div` x) + (n `mod` x) ) populations $ d2 !! (head $ filter ((==minimum d1) . (d1 !!)) [0..])