[Haskell-cafe] xkcd #287 "NP-Complete"

Donald Bruce Stewart dons at cse.unsw.edu.au
Tue Jul 10 03:47:41 EDT 2007


lemming:
> 
> On Tue, 10 Jul 2007, Donald Bruce Stewart wrote:
> 
> > These smaller NP problems really love the list monad. here's roconnor's
> > solution from #haskell:
> >
> >     import Control.Monad
> >
> >     menu = [("Mixed Fruit",215),("French Fries",275)
> >            ,("Side Salad",335),("Hot Wings",355)
> >            ,("Mozzarella Sticks",420),("Sampler Plate",580)]
> >
> >     main = mapM_ print
> >             [ map fst y
> >             | i <- [0..]
> >             , y <- replicateM i menu
> >             , sum (map snd y) == 1505 ]
> 
> Shouldn't we stay away from integer indices on lists?
> 
> [ map fst y |
>     y <- concat (iterate (liftM2 (:) menu) [[]]),
>     sum (map snd y) == 1505]

Also, wouldn't it be nice to bring back monad comprehensions...

Bring them back! No one's scared any more!

-- Don



More information about the Haskell-Cafe mailing list